diff --git a/src/lib.rs b/src/lib.rs index db6c7fe..f8ef328 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,6 +88,7 @@ use std::fmt::Debug; use std::hash::BuildHasher; use std::hash::{Hash, Hasher}; +#[derive(Clone)] pub struct DefaultHashBuilder; impl BuildHasher for DefaultHashBuilder { @@ -133,6 +134,7 @@ impl Ord for Node { } } +#[derive(Clone)] pub struct HashRing { hash_builder: S, ring: Vec>, @@ -482,4 +484,31 @@ mod tests { assert_eq!(Some(vnode2), iter.next()); assert_eq!(None, iter.next()); } + + struct TestIterStruct { + ring: HashRing, + } + + impl TestIterStruct { + pub fn print_each(&self) -> Vec { + let mut v = Vec::new(); + for node in self.ring.clone().into_iter() { + v.push(node); + } + v + } + } + + #[test] + fn into_iter_for_struct_field() { + let mut ring: HashRing = HashRing::new(); + ring.add("foo".to_string()); + ring.add("bar".to_string()); + + let s = TestIterStruct { ring }; + + let v = s.print_each(); + + assert_eq!(v.len(), 2); + } }