diff options
author | HampusM <hampus@hampusmat.com> | 2022-07-31 13:26:41 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-08-01 15:52:23 +0200 |
commit | 3383faeaf8342cf4637b6d9a9dfba30b1684edca (patch) | |
tree | 3a4e23d299d077eaf82cb09a093eaaae384e4ec2 /macros/src/util/iterator_ext.rs | |
parent | 8d2c6412fec2f35581a48433421db4b03a8d6657 (diff) |
feat: add hide impl of Injectable from documentation
This will make it so that by default the impl of Injectable is hidden from user code documentation. This commit also includes a flag for the injectable macro to disable the aforementioned feature
Diffstat (limited to 'macros/src/util/iterator_ext.rs')
-rw-r--r-- | macros/src/util/iterator_ext.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/macros/src/util/iterator_ext.rs b/macros/src/util/iterator_ext.rs new file mode 100644 index 0000000..86db6cb --- /dev/null +++ b/macros/src/util/iterator_ext.rs @@ -0,0 +1,28 @@ +use std::collections::HashMap; +use std::hash::Hash; + +pub trait IteratorExt<Item> +{ + fn find_duplicate(&mut self) -> Option<Item>; +} + +impl<Iter> IteratorExt<Iter::Item> for Iter +where + Iter: Iterator, + Iter::Item: Eq + Hash + Copy, +{ + fn find_duplicate(&mut self) -> Option<Iter::Item> + { + let mut iterated_item_map = HashMap::<Iter::Item, ()>::new(); + + for item in self { + if iterated_item_map.contains_key(&item) { + return Some(item); + } + + iterated_item_map.insert(item, ()); + } + + None + } +} |