Skip to content

Commit

Permalink
Added iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
octavonce committed Jul 8, 2019
1 parent 86f2111 commit 23b4c42
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,29 @@ impl<'a, K, V> CowHashMap<'a, K, V>

CowHashMap { inner: collection }
}

/// An iterator visiting all key-value pairs in arbitrary order.
///
/// ```rust
/// # #[macro_use] extern crate hashcow; fn main() {
/// # use std::collections::HashSet;
/// use hashcow::CowHashMap;
///
/// let mut hm: CowHashMap<str, [u8]> = CowHashMap::new();
/// let v1 = &[1, 2, 3];
/// let v2 = &[4, 5, 6];
/// hm.insert_borrowed("key1", v1);
/// hm.insert_owned("key2".to_owned(), vec![4, 5, 6]);
///
/// for (key, val) in hm.iter() {
/// // ...
/// }
/// # }
/// ```
#[inline]
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)> {
self.inner.iter().map(|(k, v)| (k.borrow(), v.borrow()))
}
}

#[macro_use]
Expand Down

0 comments on commit 23b4c42

Please sign in to comment.