summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md15
1 files changed, 12 insertions, 3 deletions
diff --git a/README.md b/README.md
index e0ec639..2af017b 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,9 @@
# collect-once-hashmap
-This crate provides a type `CollectOnceHashMap` that can be collected from an
-iterator just like a normal `std::collections::HashMap`, but it makes sure that
-a duplicated key results in an error.
+This crate provides a type `CollectOnceHashMap` (and the same for `BTreeMap`
+that can be collected from an iterator just like a normal
+`std::collections::HashMap`, but it makes sure that a duplicated key results in
+an error.
Example:
@@ -15,6 +16,14 @@ let hm = vec![(1, 1), (1, 2)]
assert!(hm.is_err());
assert!(std::matches!(hm, Err(Error::DuplicatedKey(1))));
+
+let bm = vec![(1, 1), (1, 2)]
+ .into_iter()
+ .collect::<CollectOnceBTreeMap<u8, u8>>()
+ .into_inner();
+
+assert!(bm.is_err());
+assert!(std::matches!(bm, Err(Error::DuplicatedKey(1))));
```