]> git.proxmox.com Git - cargo.git/commitdiff
use `Deref` instead of an explicit function
authorEh2406 <YeomanYaacov@gmail.com>
Wed, 7 Mar 2018 22:19:53 +0000 (17:19 -0500)
committerEh2406 <YeomanYaacov@gmail.com>
Wed, 7 Mar 2018 22:19:53 +0000 (17:19 -0500)
src/cargo/core/interning.rs
src/cargo/core/resolver/mod.rs

index f8d028b3455024ec5e0115e035ef037beba86597..9fea6503d7fffeb80b8d347d613f6c131e89a806 100644 (file)
@@ -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();
@@ -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)
     }
 }
 
index 011766d952bcbfa60aeeb57ecbeede97d8831654..f8b0b26c94fde472f5612310585dedd727dade79 100644 (file)
@@ -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(),
     };