D6593: rust-minor-fixes: remove Deref in favor of explicit methods

Alphare (Raphaël Gomès) phabricator at mercurial-scm.org
Fri Jul 5 04:35:07 EDT 2019


Alphare updated this revision to Diff 15771.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6593?vs=15740&id=15771

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6593/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6593

AFFECTED FILES
  rust/hg-core/src/dirstate/dirs_multiset.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/dirstate/dirs_multiset.rs b/rust/hg-core/src/dirstate/dirs_multiset.rs
--- a/rust/hg-core/src/dirstate/dirs_multiset.rs
+++ b/rust/hg-core/src/dirstate/dirs_multiset.rs
@@ -8,9 +8,8 @@
 //! A multiset of directory names.
 //!
 //! Used to counts the references to directories in a manifest or dirstate.
-use std::collections::hash_map::Entry;
+use std::collections::hash_map::{Entry, Iter};
 use std::collections::HashMap;
-use std::ops::Deref;
 use {DirsIterable, DirstateEntry, DirstateMapError};
 
 #[derive(PartialEq, Debug)]
@@ -18,14 +17,6 @@
     inner: HashMap<Vec<u8>, u32>,
 }
 
-impl Deref for DirsMultiset {
-    type Target = HashMap<Vec<u8>, u32>;
-
-    fn deref(&self) -> &Self::Target {
-        &self.inner
-    }
-}
-
 impl DirsMultiset {
     /// Initializes the multiset from a dirstate or a manifest.
     ///
@@ -132,6 +123,18 @@
 
         Ok(())
     }
+
+    pub fn contains_key(&self, key: &[u8]) -> bool {
+        self.inner.contains_key(key)
+    }
+
+    pub fn iter(&self) -> Iter<Vec<u8>, u32> {
+        self.inner.iter()
+    }
+
+    pub fn len(&self) -> usize {
+        self.inner.len()
+    }
 }
 
 #[cfg(test)]
@@ -176,8 +179,8 @@
             map.delete_path(b"a/b/")
         );
 
-        assert_eq!(2, *map.get(&b"a".to_vec()).unwrap());
-        assert_eq!(1, *map.get(&b"a/c".to_vec()).unwrap());
+        assert_eq!(2, *map.inner.get(&b"a".to_vec()).unwrap());
+        assert_eq!(1, *map.inner.get(&b"a/c".to_vec()).unwrap());
         eprintln!("{:?}", map);
         assert_eq!(Ok(()), map.delete_path(b"a/"));
         eprintln!("{:?}", map);
@@ -203,36 +206,36 @@
         let mut map = DirsMultiset::new(DirsIterable::Manifest(vec![]), None);
 
         map.add_path(b"a/");
-        assert_eq!(1, *map.get(&b"a".to_vec()).unwrap());
-        assert_eq!(1, *map.get(&Vec::new()).unwrap());
+        assert_eq!(1, *map.inner.get(&b"a".to_vec()).unwrap());
+        assert_eq!(1, *map.inner.get(&Vec::new()).unwrap());
         assert_eq!(2, map.len());
 
         // Non directory should be ignored
         map.add_path(b"a");
-        assert_eq!(1, *map.get(&b"a".to_vec()).unwrap());
+        assert_eq!(1, *map.inner.get(&b"a".to_vec()).unwrap());
         assert_eq!(2, map.len());
 
         // Non directory will still add its base
         map.add_path(b"a/b");
-        assert_eq!(2, *map.get(&b"a".to_vec()).unwrap());
+        assert_eq!(2, *map.inner.get(&b"a".to_vec()).unwrap());
         assert_eq!(2, map.len());
 
         // Duplicate path works
         map.add_path(b"a/");
-        assert_eq!(3, *map.get(&b"a".to_vec()).unwrap());
+        assert_eq!(3, *map.inner.get(&b"a".to_vec()).unwrap());
 
         // Nested dir adds to its base
         map.add_path(b"a/b/");
-        assert_eq!(4, *map.get(&b"a".to_vec()).unwrap());
-        assert_eq!(1, *map.get(&b"a/b".to_vec()).unwrap());
+        assert_eq!(4, *map.inner.get(&b"a".to_vec()).unwrap());
+        assert_eq!(1, *map.inner.get(&b"a/b".to_vec()).unwrap());
 
         // but not its base's base, because it already existed
         map.add_path(b"a/b/c/");
-        assert_eq!(4, *map.get(&b"a".to_vec()).unwrap());
-        assert_eq!(2, *map.get(&b"a/b".to_vec()).unwrap());
+        assert_eq!(4, *map.inner.get(&b"a".to_vec()).unwrap());
+        assert_eq!(2, *map.inner.get(&b"a/b".to_vec()).unwrap());
 
         map.add_path(b"a/c/");
-        assert_eq!(1, *map.get(&b"a/c".to_vec()).unwrap());
+        assert_eq!(1, *map.inner.get(&b"a/c".to_vec()).unwrap());
 
         let expected = DirsMultiset {
             inner: [("", 2), ("a", 5), ("a/b", 2), ("a/b/c", 1), ("a/c", 1)]



To: Alphare, #hg-reviewers
Cc: yuja, durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list