1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#[doc(hidden)]
#[macro_export]
macro_rules! define_value_map {
    ($T:ident) => {
        /// A map from [`String`]s to [`Value`](bolt_proto::Value)s used primarily to
        /// provide supplementary information to [`Client`] methods.
        #[derive(Debug, Default, Clone)]
        pub struct $T {
            pub(crate) value: ::std::collections::HashMap<std::string::String, ::bolt_proto::Value>,
        }

        impl<K, V> ::std::convert::From<::std::collections::HashMap<K, V>> for $T
        where
            K: ::std::convert::Into<::std::string::String>,
            V: ::std::convert::Into<::bolt_proto::Value>,
        {
            fn from(
                map: ::std::collections::HashMap<K, V, ::std::collections::hash_map::RandomState>,
            ) -> Self {
                Self {
                    value: map.into_iter().map(|(k, v)| (k.into(), v.into())).collect(),
                }
            }
        }

        impl<K, V> ::std::iter::FromIterator<(K, V)> for $T
        where
            K: Eq + ::std::hash::Hash + ::std::convert::Into<std::string::String>,
            V: ::std::convert::Into<::bolt_proto::Value>,
        {
            fn from_iter<T: ::std::iter::IntoIterator<Item = (K, V)>>(iter: T) -> Self {
                Self {
                    value: ::std::collections::HashMap::from_iter(
                        iter.into_iter().map(|(k, v)| (k.into(), v.into())),
                    ),
                }
            }
        }
    };
}