##// END OF EJS Templates
rust: remove Deref in favor of explicit methods...
Raphaël Gomès -
r42762:a80464e8 default
parent child Browse files
Show More
@@ -8,9 +8,8 b''
8 8 //! A multiset of directory names.
9 9 //!
10 10 //! Used to counts the references to directories in a manifest or dirstate.
11 use std::collections::hash_map::Entry;
11 use std::collections::hash_map::{Entry, Iter};
12 12 use std::collections::HashMap;
13 use std::ops::Deref;
14 13 use {DirsIterable, DirstateEntry, DirstateMapError};
15 14
16 15 #[derive(PartialEq, Debug)]
@@ -18,14 +17,6 b' pub struct DirsMultiset {'
18 17 inner: HashMap<Vec<u8>, u32>,
19 18 }
20 19
21 impl Deref for DirsMultiset {
22 type Target = HashMap<Vec<u8>, u32>;
23
24 fn deref(&self) -> &Self::Target {
25 &self.inner
26 }
27 }
28
29 20 impl DirsMultiset {
30 21 /// Initializes the multiset from a dirstate or a manifest.
31 22 ///
@@ -132,6 +123,18 b' impl DirsMultiset {'
132 123
133 124 Ok(())
134 125 }
126
127 pub fn contains_key(&self, key: &[u8]) -> bool {
128 self.inner.contains_key(key)
129 }
130
131 pub fn iter(&self) -> Iter<Vec<u8>, u32> {
132 self.inner.iter()
133 }
134
135 pub fn len(&self) -> usize {
136 self.inner.len()
137 }
135 138 }
136 139
137 140 #[cfg(test)]
@@ -176,8 +179,8 b' mod tests {'
176 179 map.delete_path(b"a/b/")
177 180 );
178 181
179 assert_eq!(2, *map.get(&b"a".to_vec()).unwrap());
180 assert_eq!(1, *map.get(&b"a/c".to_vec()).unwrap());
182 assert_eq!(2, *map.inner.get(&b"a".to_vec()).unwrap());
183 assert_eq!(1, *map.inner.get(&b"a/c".to_vec()).unwrap());
181 184 eprintln!("{:?}", map);
182 185 assert_eq!(Ok(()), map.delete_path(b"a/"));
183 186 eprintln!("{:?}", map);
@@ -203,36 +206,36 b' mod tests {'
203 206 let mut map = DirsMultiset::new(DirsIterable::Manifest(vec![]), None);
204 207
205 208 map.add_path(b"a/");
206 assert_eq!(1, *map.get(&b"a".to_vec()).unwrap());
207 assert_eq!(1, *map.get(&Vec::new()).unwrap());
209 assert_eq!(1, *map.inner.get(&b"a".to_vec()).unwrap());
210 assert_eq!(1, *map.inner.get(&Vec::new()).unwrap());
208 211 assert_eq!(2, map.len());
209 212
210 213 // Non directory should be ignored
211 214 map.add_path(b"a");
212 assert_eq!(1, *map.get(&b"a".to_vec()).unwrap());
215 assert_eq!(1, *map.inner.get(&b"a".to_vec()).unwrap());
213 216 assert_eq!(2, map.len());
214 217
215 218 // Non directory will still add its base
216 219 map.add_path(b"a/b");
217 assert_eq!(2, *map.get(&b"a".to_vec()).unwrap());
220 assert_eq!(2, *map.inner.get(&b"a".to_vec()).unwrap());
218 221 assert_eq!(2, map.len());
219 222
220 223 // Duplicate path works
221 224 map.add_path(b"a/");
222 assert_eq!(3, *map.get(&b"a".to_vec()).unwrap());
225 assert_eq!(3, *map.inner.get(&b"a".to_vec()).unwrap());
223 226
224 227 // Nested dir adds to its base
225 228 map.add_path(b"a/b/");
226 assert_eq!(4, *map.get(&b"a".to_vec()).unwrap());
227 assert_eq!(1, *map.get(&b"a/b".to_vec()).unwrap());
229 assert_eq!(4, *map.inner.get(&b"a".to_vec()).unwrap());
230 assert_eq!(1, *map.inner.get(&b"a/b".to_vec()).unwrap());
228 231
229 232 // but not its base's base, because it already existed
230 233 map.add_path(b"a/b/c/");
231 assert_eq!(4, *map.get(&b"a".to_vec()).unwrap());
232 assert_eq!(2, *map.get(&b"a/b".to_vec()).unwrap());
234 assert_eq!(4, *map.inner.get(&b"a".to_vec()).unwrap());
235 assert_eq!(2, *map.inner.get(&b"a/b".to_vec()).unwrap());
233 236
234 237 map.add_path(b"a/c/");
235 assert_eq!(1, *map.get(&b"a/c".to_vec()).unwrap());
238 assert_eq!(1, *map.inner.get(&b"a/c".to_vec()).unwrap());
236 239
237 240 let expected = DirsMultiset {
238 241 inner: [("", 2), ("a", 5), ("a/b", 2), ("a/b/c", 1), ("a/c", 1)]
General Comments 0
You need to be logged in to leave comments. Login now