Skip to content

Commit 98480e8

Browse files
committed
use Deref instead of an explicit function
1 parent 827fdf8 commit 98480e8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/cargo/core/interning.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use std::fmt;
21
use std::sync::RwLock;
32
use std::collections::HashSet;
43
use std::slice;
54
use std::str;
65
use std::mem;
76
use std::cmp::Ordering;
7+
use std::ops::Deref;
88

99
pub fn leek(s: String) -> &'static str {
1010
let boxed = s.into_boxed_str();
@@ -38,23 +38,23 @@ impl InternedString {
3838
cache.insert(s);
3939
InternedString { ptr: s.as_ptr(), len: s.len() }
4040
}
41-
pub fn to_inner(&self) -> &'static str {
41+
}
42+
43+
impl Deref for InternedString {
44+
type Target = str;
45+
46+
fn deref(&self) -> &'static str {
4247
unsafe {
4348
let slice = slice::from_raw_parts(self.ptr, self.len);
44-
str::from_utf8_unchecked(slice)
49+
&str::from_utf8_unchecked(slice)
4550
}
4651
}
4752
}
4853

49-
impl fmt::Debug for InternedString {
50-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51-
write!(f, "InternedString {{ {} }}", self.to_inner())
52-
}
53-
}
54-
5554
impl Ord for InternedString {
5655
fn cmp(&self, other: &InternedString) -> Ordering {
57-
self.to_inner().cmp(&other.to_inner())
56+
let str: &str = &*self;
57+
str.cmp(&*other)
5858
}
5959
}
6060

src/cargo/core/resolver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ pub fn resolve(summaries: &[(Summary, Method)],
371371
metadata: BTreeMap::new(),
372372
replacements: cx.resolve_replacements(),
373373
features: cx.resolve_features.iter().map(|(k, v)| {
374-
(k.clone(), v.iter().map(|x| x.to_inner().to_string()).collect())
374+
(k.clone(), v.iter().map(|x| x.to_string()).collect())
375375
}).collect(),
376376
unused_patches: Vec::new(),
377377
};

0 commit comments

Comments
 (0)