1macro_rules! do_impl {
2 (
3 MapIter for $name:ident, $impl_for:ty,
4 ($key:ty, $key_item:ty, $keys_iter:ty),
5 ($value:ty, $value_item:ty, $values_iter:ty); $($gen:tt)*
6 ) => {
7 impl<'a, $($gen)*> $crate::map::HasMapData for $impl_for {
8 type Key = $key;
9 type Value = $value;
10 }
11 impl<'a, $($gen)*> $crate::map::MapIter<'a> for $impl_for {
12 type KeyRef = $key_item;
13 type ValueRef = $value_item;
14 type IterKeysRef = $keys_iter;
15 type IterValuesRef = $values_iter;
16 fn keys(&'a self) -> $keys_iter {
17 $name::keys(self)
18 }
19 fn values(&'a self) -> $values_iter {
20 $name::values(self)
21 }
22 }
23 };
24 (
25 MapIterMut for $name:ident, $impl_for:ty,
26 ($key:ty, $key_item:ty, $keys_iter:ty),
27 ($value:ty, $value_item:ty, $values_iter:ty),
28 ($value_item_mut:ty, $values_mut_iter:ty); $($gen:tt)*
29 ) => {
30 do_impl!(MapIter for $name, $impl_for,
31 ($key, $key_item, $keys_iter),
32 ($value, $value_item, $values_iter); $($gen)*);
33 impl<'a, $($gen)*> $crate::map::MapIterMut<'a> for $impl_for {
34 type ValueMut = $value_item_mut;
35 type IterValuesMut = $values_mut_iter;
36
37 fn values_mut(&'a mut self) -> $values_mut_iter {
38 $name::values_mut(self)
39 }
40 }
41 };
42}
43
44impl<T> super::HasData for [T] {
45 type Item = T;
46}
47impl<T> super::HasMapData for [T] {
48 type Key = usize;
49 type Value = T;
50}
51
52cfg_if! {
53 if #[cfg(feature = "alloc")] {
54 cfg_if! {
55 if #[cfg(feature = "std")] {
56 use std::collections;
57 } else {
58 use alloc::{self as collections, Vec};
59 }
60 }
61 use self::collections::{BTreeMap, BTreeSet, VecDeque, btree_map};
62
63 impl<T: Ord> super::HasMapData for BTreeSet<T> {
64 type Key = T;
65 type Value = T;
66 }
67 impl<T> super::HasMapData for Vec<T> {
68 type Key = usize;
69 type Value = T;
70 }
71 impl<T> super::HasMapData for VecDeque<T> {
72 type Key = usize;
73 type Value = T;
74 }
75
76 do_impl!(MapIterMut for BTreeMap, BTreeMap<K, V>,
77 (K, &'a K, btree_map::Keys<'a, K, V>),
78 (V, &'a V, btree_map::Values<'a, K, V>),
79 (&'a mut V, btree_map::ValuesMut<'a, K, V>); K: 'a + Ord, V: 'a);
80 }
81}
82
83cfg_if! {
84 if #[cfg(feature = "std")] {
85 use std::collections::{HashMap, HashSet, hash_map};
86 use std::hash::Hash;
87
88 impl<T: Hash + Eq> super::HasMapData for HashSet<T> {
89 type Key = T;
90 type Value = T;
91 }
92
93 do_impl!(MapIterMut for HashMap, HashMap<K, V>,
94 (K, &'a K, hash_map::Keys<'a, K, V>),
95 (V, &'a V, hash_map::Values<'a, K, V>),
96 (&'a mut V, hash_map::ValuesMut<'a, K, V>); K: 'a + Hash + Eq, V: 'a);
97 }
98}