1 | use crate::InternalString; |
2 | |
3 | use super::Error; |
4 | |
5 | pub(crate) struct KeySerializer; |
6 | |
7 | impl serde::ser::Serializer for KeySerializer { |
8 | type Ok = InternalString; |
9 | type Error = Error; |
10 | type SerializeSeq = serde::ser::Impossible<InternalString, Error>; |
11 | type SerializeTuple = serde::ser::Impossible<InternalString, Error>; |
12 | type SerializeTupleStruct = serde::ser::Impossible<InternalString, Error>; |
13 | type SerializeTupleVariant = serde::ser::Impossible<InternalString, Error>; |
14 | type SerializeMap = serde::ser::Impossible<InternalString, Error>; |
15 | type SerializeStruct = serde::ser::Impossible<InternalString, Error>; |
16 | type SerializeStructVariant = serde::ser::Impossible<InternalString, Error>; |
17 | |
18 | fn serialize_bool(self, _v: bool) -> Result<InternalString, Self::Error> { |
19 | Err(Error::KeyNotString) |
20 | } |
21 | |
22 | fn serialize_i8(self, _v: i8) -> Result<InternalString, Self::Error> { |
23 | Err(Error::KeyNotString) |
24 | } |
25 | |
26 | fn serialize_i16(self, _v: i16) -> Result<InternalString, Self::Error> { |
27 | Err(Error::KeyNotString) |
28 | } |
29 | |
30 | fn serialize_i32(self, _v: i32) -> Result<InternalString, Self::Error> { |
31 | Err(Error::KeyNotString) |
32 | } |
33 | |
34 | fn serialize_i64(self, _v: i64) -> Result<InternalString, Self::Error> { |
35 | Err(Error::KeyNotString) |
36 | } |
37 | |
38 | fn serialize_u8(self, _v: u8) -> Result<InternalString, Self::Error> { |
39 | Err(Error::KeyNotString) |
40 | } |
41 | |
42 | fn serialize_u16(self, _v: u16) -> Result<InternalString, Self::Error> { |
43 | Err(Error::KeyNotString) |
44 | } |
45 | |
46 | fn serialize_u32(self, _v: u32) -> Result<InternalString, Self::Error> { |
47 | Err(Error::KeyNotString) |
48 | } |
49 | |
50 | fn serialize_u64(self, _v: u64) -> Result<InternalString, Self::Error> { |
51 | Err(Error::KeyNotString) |
52 | } |
53 | |
54 | fn serialize_f32(self, _v: f32) -> Result<InternalString, Self::Error> { |
55 | Err(Error::KeyNotString) |
56 | } |
57 | |
58 | fn serialize_f64(self, _v: f64) -> Result<InternalString, Self::Error> { |
59 | Err(Error::KeyNotString) |
60 | } |
61 | |
62 | fn serialize_char(self, _v: char) -> Result<InternalString, Self::Error> { |
63 | Err(Error::KeyNotString) |
64 | } |
65 | |
66 | fn serialize_str(self, value: &str) -> Result<InternalString, Self::Error> { |
67 | Ok(InternalString::from(value)) |
68 | } |
69 | |
70 | fn serialize_bytes(self, _value: &[u8]) -> Result<InternalString, Self::Error> { |
71 | Err(Error::KeyNotString) |
72 | } |
73 | |
74 | fn serialize_none(self) -> Result<InternalString, Self::Error> { |
75 | Err(Error::KeyNotString) |
76 | } |
77 | |
78 | fn serialize_some<T: ?Sized>(self, _value: &T) -> Result<InternalString, Self::Error> |
79 | where |
80 | T: serde::ser::Serialize, |
81 | { |
82 | Err(Error::KeyNotString) |
83 | } |
84 | |
85 | fn serialize_unit(self) -> Result<InternalString, Self::Error> { |
86 | Err(Error::KeyNotString) |
87 | } |
88 | |
89 | fn serialize_unit_struct(self, _name: &'static str) -> Result<InternalString, Self::Error> { |
90 | Err(Error::KeyNotString) |
91 | } |
92 | |
93 | fn serialize_unit_variant( |
94 | self, |
95 | _name: &'static str, |
96 | _variant_index: u32, |
97 | variant: &'static str, |
98 | ) -> Result<InternalString, Self::Error> { |
99 | Ok(variant.into()) |
100 | } |
101 | |
102 | fn serialize_newtype_struct<T: ?Sized>( |
103 | self, |
104 | _name: &'static str, |
105 | value: &T, |
106 | ) -> Result<InternalString, Self::Error> |
107 | where |
108 | T: serde::ser::Serialize, |
109 | { |
110 | value.serialize(self) |
111 | } |
112 | |
113 | fn serialize_newtype_variant<T: ?Sized>( |
114 | self, |
115 | _name: &'static str, |
116 | _variant_index: u32, |
117 | _variant: &'static str, |
118 | _value: &T, |
119 | ) -> Result<InternalString, Self::Error> |
120 | where |
121 | T: serde::ser::Serialize, |
122 | { |
123 | Err(Error::KeyNotString) |
124 | } |
125 | |
126 | fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> { |
127 | Err(Error::KeyNotString) |
128 | } |
129 | |
130 | fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> { |
131 | Err(Error::KeyNotString) |
132 | } |
133 | |
134 | fn serialize_tuple_struct( |
135 | self, |
136 | _name: &'static str, |
137 | _len: usize, |
138 | ) -> Result<Self::SerializeTupleStruct, Self::Error> { |
139 | Err(Error::KeyNotString) |
140 | } |
141 | |
142 | fn serialize_tuple_variant( |
143 | self, |
144 | _name: &'static str, |
145 | _variant_index: u32, |
146 | _variant: &'static str, |
147 | _len: usize, |
148 | ) -> Result<Self::SerializeTupleVariant, Self::Error> { |
149 | Err(Error::KeyNotString) |
150 | } |
151 | |
152 | fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> { |
153 | Err(Error::KeyNotString) |
154 | } |
155 | |
156 | fn serialize_struct( |
157 | self, |
158 | _name: &'static str, |
159 | _len: usize, |
160 | ) -> Result<Self::SerializeStruct, Self::Error> { |
161 | Err(Error::KeyNotString) |
162 | } |
163 | |
164 | fn serialize_struct_variant( |
165 | self, |
166 | _name: &'static str, |
167 | _variant_index: u32, |
168 | _variant: &'static str, |
169 | _len: usize, |
170 | ) -> Result<Self::SerializeStructVariant, Self::Error> { |
171 | Err(Error::KeyNotString) |
172 | } |
173 | } |
174 | |