Skip to content

Commit

Permalink
use Deref instead of an explicit function
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Mar 7, 2018
1 parent 827fdf8 commit 98480e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/cargo/core/interning.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::fmt;
use std::sync::RwLock;
use std::collections::HashSet;
use std::slice;
use std::str;
use std::mem;
use std::cmp::Ordering;
use std::ops::Deref;

pub fn leek(s: String) -> &'static str {
let boxed = s.into_boxed_str();
Expand Down Expand Up @@ -38,23 +38,23 @@ impl InternedString {
cache.insert(s);
InternedString { ptr: s.as_ptr(), len: s.len() }
}
pub fn to_inner(&self) -> &'static str {
}

impl Deref for InternedString {
type Target = str;

fn deref(&self) -> &'static str {
unsafe {
let slice = slice::from_raw_parts(self.ptr, self.len);
str::from_utf8_unchecked(slice)
&str::from_utf8_unchecked(slice)
}
}
}

impl fmt::Debug for InternedString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "InternedString {{ {} }}", self.to_inner())
}
}

impl Ord for InternedString {
fn cmp(&self, other: &InternedString) -> Ordering {
self.to_inner().cmp(&other.to_inner())
let str: &str = &*self;
str.cmp(&*other)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub fn resolve(summaries: &[(Summary, Method)],
metadata: BTreeMap::new(),
replacements: cx.resolve_replacements(),
features: cx.resolve_features.iter().map(|(k, v)| {
(k.clone(), v.iter().map(|x| x.to_inner().to_string()).collect())
(k.clone(), v.iter().map(|x| x.to_string()).collect())
}).collect(),
unused_patches: Vec::new(),
};
Expand Down

0 comments on commit 98480e8

Please sign in to comment.