File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,42 @@ use core::hash::{BuildHasher, Hash};
28
28
use core:: marker:: PhantomData ;
29
29
30
30
use crate :: IndexMap ;
31
+ use crate :: map:: Slice as MapSlice ;
32
+ use crate :: set:: Slice as SetSlice ;
33
+
34
+ /// Serializes a `map::Slice` as an ordered sequence.
35
+ ///
36
+ /// This behaves like [`crate::serde_seq`] for `IndexMap`, serializing a sequence
37
+ /// of `(key, value)` pairs, rather than as a map that might not preserver order.
38
+ ///
39
+ /// Requires crate feature `"serde"` or `"serde-1"`
40
+ impl < K , V > Serialize for MapSlice < K , V >
41
+ where
42
+ K : Serialize ,
43
+ V : Serialize ,
44
+ {
45
+ fn serialize < T > ( & self , serializer : T ) -> Result < T :: Ok , T :: Error >
46
+ where
47
+ T : Serializer ,
48
+ {
49
+ serializer. collect_seq ( self )
50
+ }
51
+ }
52
+
53
+ /// Serializes a `set::Slice` as an ordered sequence.
54
+ ///
55
+ /// Requires crate feature `"serde"` or `"serde-1"`
56
+ impl < T > Serialize for SetSlice < T >
57
+ where
58
+ T : Serialize ,
59
+ {
60
+ fn serialize < Se > ( & self , serializer : Se ) -> Result < Se :: Ok , Se :: Error >
61
+ where
62
+ Se : Serializer ,
63
+ {
64
+ serializer. collect_seq ( self )
65
+ }
66
+ }
31
67
32
68
/// Serializes an `IndexMap` as an ordered sequence.
33
69
///
You can’t perform that action at this time.
0 commit comments