redisclient/protocol/
maps.rs

1#[macro_export]
2macro_rules! implement_serialization_for_maps {
3    ($($t:ident),*) => {
4        $(
5            impl<K, V> RedisSerializationProtocol for $t<K, V>
6            where
7                K: RedisSerializationProtocol + Hash + Eq,
8                V: RedisSerializationProtocol,
9            {
10                fn serialization(&self) -> Vec<u8> {
11                    unimplemented!()
12                }
13            }
14        )*
15    };
16}
17
18#[macro_export]
19macro_rules! implement_deserialization_for_maps {
20    ($($t:ident),*) => {
21        $(
22            impl<K, V> RedisDeserializationProtocol for $t::<K, V>
23            where
24                K: RedisDeserializationProtocol + Eq + Hash + Ord,
25                V: RedisDeserializationProtocol,
26            {
27                fn deserialization(reply: Reply) -> RedisResult<Self> {
28                    // TODO: ugly code, refactor !!!
29                    match reply {
30                        Reply::Arrays(array) => {
31                            let hash = array
32                                .chunks(2)
33                                .map(|chunk| {
34                                    let field = &chunk[0];
35                                    let value = &chunk[1];
36                                    (
37                                        <K>::deserialization(field.clone()).unwrap(),
38                                        <V>::deserialization(value.clone()).unwrap(), // TODO: remove clone and unwrap
39                                    )
40                                })
41                                .collect();
42                            Ok(hash)
43                        }
44                        _ => Err(RedisError::custom(TypeError, "miss type")),
45                    }
46                }
47            }
48        )*
49    };
50}