Crates.io | collect-once-hashmap |
lib.rs | collect-once-hashmap |
version | 0.2.0 |
source | src |
created_at | 2021-09-01 08:12:30.911776 |
updated_at | 2021-09-01 13:20:38.322539 |
description | A hashmap that can be collected only when there are unique keys in the iterator |
homepage | https://git.beyermatthi.as/collect-once-hashmap |
repository | https://git.beyermatthi.as/collect-once-hashmap |
max_upload_size | |
id | 445489 |
size | 24,947 |
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:
# use collect_once_hashmap::{CollectOnceHashMap, Error};
let hm = vec![(1, 1), (1, 2)]
.into_iter()
.collect::<CollectOnceHashMap<u8, u8>>()
.into_inner();
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))));
MPL-2.0 (c) Matthias Beyer