Debian Codegraph @

src/serde.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 //! Implementations of `serde::Serialize` and `serde::Deserialize` for
2 //! `BiHashMap` and `BiBTreeMap`.
3 //!
4 //! You do not need to import anything from this module to use this
5 //! functionality, simply enable the `serde` feature in your dependency
6 //! manifest. Note that currently, this requires the `std` feature to also be
7 //! enabled, and thus cannot be used in `no_std` enviroments.
8 //!
9 //! # Examples
10 //!
11 //! You can easily serialize and deserialize bimaps with any serde-compatbile
12 //! serializer or deserializer.
13 //!
14 //! Serializing and deserializing a [`BiHashMap`]:
15 //!
16 //! ```
17 //! # use bimap::BiHashMap;
18 //! // create a new bimap
19 //! let mut map = BiHashMap::new();
20 //!
21 //! // insert some pairs
22 //! map.insert('A', 1);
23 //! map.insert('B', 2);
24 //! map.insert('C', 3);
25 //!
26 //! // convert the bimap to json
27 //! let json = serde_json::to_string(&map).unwrap();
28 //!
29 //! // convert the json back into a bimap
30 //! let map2 = serde_json::from_str(&json).unwrap();
31 //!
32 //! // check that the two bimaps are equal
33 //! assert_eq!(map, map2);
34 //! ```
35 //!
36 //! Serializing and deserializing a [`BiBTreeMap`]:
37 //! ```
38 //! # use bimap::BiBTreeMap;
39 //! // create a new bimap
40 //! let mut map = BiBTreeMap::new();
41 //!
42 //! // insert some pairs
43 //! map.insert('A', 3);
44 //! map.insert('B', 2);
45 //! map.insert('C', 1);
46 //!
47 //! // convert the bimap to json
48 //! let json = serde_json::to_string(&map).unwrap();
49 //!
50 //! // convert the json back into a bimap
51 //! let map2 = serde_json::from_str(&json).unwrap();
52 //!
53 //! // check that the two bimaps are equal
54 //! assert_eq!(map, map2);
55 //! ```
56 //!
57 //! Of course, this is only possible for bimaps where the values also implement
58 //! `Serialize` and `Deserialize` respectively:
59 //!
60 //! ```compile_fail
61 //! # use bimap::BiHashMap;
62 //! // this type doesn't implement Serialize or Deserialize!
63 //! #[derive(PartialEq, Eq, Hash)]
64 //! enum MyEnum { A, B, C }
65 //!
66 //! // create a bimap and add some pairs
67 //! let mut map = BiHashMap::new();
68 //! map.insert(MyEnum::A, 1);
69 //! map.insert(MyEnum::B, 2);
70 //! map.insert(MyEnum::C, 3);
71 //!
72 //! // this line will cause the code to fail to compile
73 //! let json = serde_json::to_string(&map).unwrap();
74 //! ```
75 //!
76 //! # Implementation details
77 //!
78 //! Bimaps are serialized and deserialized as a map data type in serde.
79 //! Consequentially, it is possible to serialize and deserialize bimaps to/from
80 //! other types that are represented the same way. *This is considered an
81 //! implementation detail and should not be relied upon.*
82 //!
83 //! For example, a bimap can be deserialized from the serialized form of a
84 //! standard [`HashMap`]. However, *deserializing a bimap silently overwrites
85 //! any conflicting pairs*, leading to non-deterministic results.
86 //! ```
87 //! # use std::collections::HashMap;
88 //! # use bimap::BiHashMap;
89 //! // construct a regular map
90 //! let mut map = HashMap::new();
91 //!
92 //! // insert some entries
93 //! // note that both 'B' and 'C' are associated with the value 2 here
94 //! map.insert('A', 1);
95 //! map.insert('B', 2);
96 //! map.insert('C', 2);
97 //!
98 //! // serialize the map
99 //! let json = serde_json::to_string(&map).unwrap();
100 //!
101 //! // deserialize it into a bimap
102 //! let bimap: BiHashMap<char, i32> = serde_json::from_str(&json).unwrap();
103 //!
104 //! // deserialization succeeds, but the bimap is now in a non-deterministic
105 //! // state - either ('B', 2) or ('C', 2) will have been overwritten while
106 //! // deserializing, but this depends on the iteration order of the original
107 //! // HashMap that was serialized.
108 //!
109 //! // we can still demonstrate that certain properties of the bimap are still
110 //! // in a known state, but this shouldn't be relied upon
111 //! assert_eq!(bimap.len(), 2);
112 //! assert_eq!(bimap.get_by_left(&'A'), Some(&1));
113 //! assert!(bimap.get_by_left(&'B') == Some(&2) || bimap.get_by_left(&'C') == Some(&2))
114 //! ```
115 //!
116 //! The reverse is also possible: bimaps may be serialized and then
117 //! deserialized as other compatible types, such as a [`HashMap`].
118 //!
119 //! ```
120 //! # use std::collections::HashMap;
121 //! # use bimap::BiHashMap;
122 //! // construct a bimap
123 //! let mut bimap = BiHashMap::new();
124 //!
125 //! // insert some pairs
126 //! bimap.insert('A', 1);
127 //! bimap.insert('B', 2);
128 //! bimap.insert('C', 3);
129 //!
130 //! // serialize the bimap
131 //! let json = serde_json::to_string(&bimap).unwrap();
132 //!
133 //! // deserialize it as a regular map
134 //! let map: HashMap<char, i32> = serde_json::from_str(&json).unwrap();
135 //!
136 //! // this succeeds and the result is sensible, but this is still an
137 //! // implementation detail and shouldn't be relied upon.
138 //! assert_eq!(map.len(), 3);
139 //! assert_eq!(map[&'A'], 1);
140 //! assert_eq!(map[&'B'], 2);
141 //! assert_eq!(map[&'C'], 3);
142 //! ```
143 //! [`BiHashMap`]: crate::BiHashMap
144 //! [`BiBTreeMap`]: crate::BiBTreeMap
145 //! [`HashMap`]: https://doc.rust-lang.org/std/collections/struct.HashMap.html
146
147 use craterust-analyzer cargo bimap 0.6.3 crate/::{BiBTreeMaprust-analyzer cargo bimap 0.6.3 btree/BiBTreeMap#, BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#};
148 use serderust-analyzer cargo serde 1.0.229 crate/::{
149 derust-analyzer cargo serde_core 1.0.229 de/::{MapAccessrust-analyzer cargo serde_core 1.0.229 de/MapAccess#, Visitorrust-analyzer cargo serde_core 1.0.229 de/Visitor#},
150 Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#,
151 };
152 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
153 defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/::Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
154 fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# as FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#},
155 hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::{BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#},
156 markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
157 };
158
159 /// Serializer for `BiHashMap`
160 impl<L, R, LS, RS> Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# for BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#<L, R, LS, RS>
161 where
162 L: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
163 R: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
164 LS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
165 RS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
166 {
167 fn serializerust-analyzer cargo bimap 0.6.3 serde/impl#[`BiHashMap<L, R, LS, RS>`][Serialize]serialize().<S: Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#>(&self, ser: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#> {
168 ser.collect_maprust-analyzer cargo serde_core 1.0.229 ser/Serializer#collect_map().(self.iterrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]iter().())
169 }
170 }
171
172 /// Visitor to construct `BiHashMap` from serialized map entries
173 struct BiHashMapVisitorrust-analyzer cargo bimap 0.6.3 serde/BiHashMapVisitor#<L, R, LS, RS> {
174 markerrust-analyzer cargo bimap 0.6.3 serde/BiHashMapVisitor#marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#<L, R, LS, RS>>,
175 }
176
177 impl<'de, L, R, LS, RS> Visitorrust-analyzer cargo serde_core 1.0.229 de/Visitor#<'de> for BiHashMapVisitorrust-analyzer cargo bimap 0.6.3 serde/BiHashMapVisitor#<L, R, LS, RS>
178 where
179 L: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
180 R: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
181 LS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
182 RS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
183 {
184 fn expectingrust-analyzer cargo bimap 0.6.3 serde/impl#[`BiHashMapVisitor<L, R, LS, RS>`][`Visitor<'de>`]expecting().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
185 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "a map")
186 }
187
188 type Valuerust-analyzer cargo bimap 0.6.3 serde/impl#[`BiHashMapVisitor<L, R, LS, RS>`][`Visitor<'de>`]Value# = BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#<L, R, LS, RS>;
189 fn visit_maprust-analyzer cargo bimap 0.6.3 serde/impl#[`BiHashMapVisitor<L, R, LS, RS>`][`Visitor<'de>`]visit_map().<A: MapAccessrust-analyzer cargo serde_core 1.0.229 de/MapAccess#<'de>>(self, mut entries: A) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bimap 0.6.3 serde/impl#[`BiHashMapVisitor<L, R, LS, RS>`][`Visitor<'de>`]::Valuerust-analyzer cargo serde_core 1.0.229 de/Visitor#Value#, A::Errorrust-analyzer cargo serde_core 1.0.229 de/MapAccess#Error#> {
190 let mut map = match entries.size_hintrust-analyzer cargo serde_core 1.0.229 de/MapAccess#size_hint().() {
191 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) => BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#::<L, R, LS, RS>::with_capacity_and_hashersrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]with_capacity_and_hashers().(
192 s,
193 LS::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().(),
194 RS::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().(),
195 ),
196 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#::<L, R, LS, RS>::with_hashersrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]with_hashers().(LS::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().(), RS::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().()),
197 };
198 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((l, r)) = entries.next_entryrust-analyzer cargo serde_core 1.0.229 de/MapAccess#next_entry().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
199 map.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().(l, r);
200 }
201 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(map)
202 }
203 }
204
205 /// Deserializer for `BiHashMap`
206 impl<'de, L, R, LS, RS> Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> for BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#<L, R, LS, RS>
207 where
208 L: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
209 R: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
210 LS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
211 RS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
212 {
213 fn deserializerust-analyzer cargo bimap 0.6.3 serde/impl#[`BiHashMap<L, R, LS, RS>`][`Deserialize<'de>`]deserialize().<D: Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>>(de: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bimap 0.6.3 serde/impl#[`BiHashMap<L, R, LS, RS>`][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#> {
214 de.deserialize_maprust-analyzer cargo serde_core 1.0.229 de/Deserializer#deserialize_map().(BiHashMapVisitorrust-analyzer cargo bimap 0.6.3 serde/BiHashMapVisitor#::<L, R, LS, RS> {
215 markerrust-analyzer cargo bimap 0.6.3 serde/BiHashMapVisitor#marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/impl#[`PhantomData<T>`][Default]default().(),
216 })
217 }
218 }
219
220 /// Serializer for `BiBTreeMap`
221 impl<L, R> Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# for BiBTreeMaprust-analyzer cargo bimap 0.6.3 btree/BiBTreeMap#<L, R>
222 where
223 L: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# + Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#,
224 R: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# + Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#,
225 {
226 fn serializerust-analyzer cargo bimap 0.6.3 serde/impl#[`BiBTreeMap<L, R>`][Serialize]serialize().<S: Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#>(&self, ser: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#> {
227 ser.collect_maprust-analyzer cargo serde_core 1.0.229 ser/Serializer#collect_map().(self.iterrust-analyzer cargo bimap 0.6.3 btree/impl#[`BiBTreeMap<L, R>`]iter().())
228 }
229 }
230
231 /// Visitor to construct `BiBTreeMap` from serialized map entries
232 struct BiBTreeMapVisitorrust-analyzer cargo bimap 0.6.3 serde/BiBTreeMapVisitor#<L, R> {
233 markerrust-analyzer cargo bimap 0.6.3 serde/BiBTreeMapVisitor#marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<BiBTreeMaprust-analyzer cargo bimap 0.6.3 btree/BiBTreeMap#<L, R>>,
234 }
235
236 impl<'de, L, R> Visitorrust-analyzer cargo serde_core 1.0.229 de/Visitor#<'de> for BiBTreeMapVisitorrust-analyzer cargo bimap 0.6.3 serde/BiBTreeMapVisitor#<L, R>
237 where
238 L: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#,
239 R: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#,
240 {
241 fn expectingrust-analyzer cargo bimap 0.6.3 serde/impl#[`BiBTreeMapVisitor<L, R>`][`Visitor<'de>`]expecting().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
242 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "a map")
243 }
244
245 type Valuerust-analyzer cargo bimap 0.6.3 serde/impl#[`BiBTreeMapVisitor<L, R>`][`Visitor<'de>`]Value# = BiBTreeMaprust-analyzer cargo bimap 0.6.3 btree/BiBTreeMap#<L, R>;
246 fn visit_maprust-analyzer cargo bimap 0.6.3 serde/impl#[`BiBTreeMapVisitor<L, R>`][`Visitor<'de>`]visit_map().<A: MapAccessrust-analyzer cargo serde_core 1.0.229 de/MapAccess#<'de>>(self, mut entries: A) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bimap 0.6.3 serde/impl#[`BiBTreeMapVisitor<L, R>`][`Visitor<'de>`]::Valuerust-analyzer cargo serde_core 1.0.229 de/Visitor#Value#, A::Errorrust-analyzer cargo serde_core 1.0.229 de/MapAccess#Error#> {
247 let mut map = BiBTreeMaprust-analyzer cargo bimap 0.6.3 btree/BiBTreeMap#::newrust-analyzer cargo bimap 0.6.3 btree/impl#[`BiBTreeMap<L, R>`]new().();
248 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((l, r)) = entries.next_entryrust-analyzer cargo serde_core 1.0.229 de/MapAccess#next_entry().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
249 map.insertrust-analyzer cargo bimap 0.6.3 btree/impl#[`BiBTreeMap<L, R>`]insert().(l, r);
250 }
251 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(map)
252 }
253 }
254
255 /// Deserializer for `BiBTreeMap`
256 impl<'de, L, R> Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> for BiBTreeMaprust-analyzer cargo bimap 0.6.3 btree/BiBTreeMap#<L, R>
257 where
258 L: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#,
259 R: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#,
260 {
261 fn deserializerust-analyzer cargo bimap 0.6.3 serde/impl#[`BiBTreeMap<L, R>`][`Deserialize<'de>`]deserialize().<D: Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>>(de: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bimap 0.6.3 serde/impl#[`BiBTreeMap<L, R>`][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#> {
262 de.deserialize_maprust-analyzer cargo serde_core 1.0.229 de/Deserializer#deserialize_map().(BiBTreeMapVisitorrust-analyzer cargo bimap 0.6.3 serde/BiBTreeMapVisitor# {
263 markerrust-analyzer cargo bimap 0.6.3 serde/BiBTreeMapVisitor#marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/impl#[`PhantomData<T>`][Default]default().(),
264 })
265 }
266 }
267
268 #[cfg(test)]
269 mod testsrust-analyzer cargo bimap 0.6.3 serde/tests/ {
270 use superrust-analyzer cargo bimap 0.6.3 serde/::*;
271 use serderust-analyzer cargo serde 1.0.229 crate/::derust-analyzer cargo serde_core 1.0.229 de/::valuerust-analyzer cargo serde_core 1.0.229 de/value/::Errorrust-analyzer cargo serde_core 1.0.229 de/value/Error#;
272 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::BuildHasherDefaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasherDefault#;
273
274 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
275 fn serde_hashrust-analyzer cargo bimap 0.6.3 serde/tests/serde_hash().() {
276 let mut bimap = BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#::newrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R>`]new().();
277 bimap.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().('a', 1);
278 bimap.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().('b', 2);
279 bimap.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().('c', 3);
280
281 let json = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_stringrust-analyzer cargo serde_json 1.0.151 ser/to_string().(&bimap).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
282 let bimap2 = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::from_strrust-analyzer cargo serde_json 1.0.151 de/from_str().(&json).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
283
284 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bimap, bimap2);
285 }
286
287 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
288 fn serde_hash_w_fnv_hasherrust-analyzer cargo bimap 0.6.3 serde/tests/serde_hash_w_fnv_hasher().() {
289 let hasher_builder = BuildHasherDefaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasherDefault#::<fnvrust-analyzer cargo fnv 1.0.7 crate/::FnvHasherrust-analyzer cargo fnv 1.0.7 FnvHasher#>::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impl#[`BuildHasherDefault<H>`][Default]default().();
290 let mut bimap = BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#::<
291 char,
292 u8,
293 BuildHasherDefaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasherDefault#<fnvrust-analyzer cargo fnv 1.0.7 crate/::FnvHasherrust-analyzer cargo fnv 1.0.7 FnvHasher#>,
294 BuildHasherDefaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasherDefault#<fnvrust-analyzer cargo fnv 1.0.7 crate/::FnvHasherrust-analyzer cargo fnv 1.0.7 FnvHasher#>,
295 >::with_capacity_and_hashersrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]with_capacity_and_hashers().(
296 4, hasher_builder.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impl#[`BuildHasherDefault<H>`][Clone]clone().(), hasher_builder.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impl#[`BuildHasherDefault<H>`][Clone]clone().()
297 );
298 bimap.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().('f', 1);
299 bimap.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().('g', 2);
300 bimap.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().('h', 3);
301
302 let json = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_stringrust-analyzer cargo serde_json 1.0.151 ser/to_string().(&bimap).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
303 let bimap2 = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::from_strrust-analyzer cargo serde_json 1.0.151 de/from_str().(&json).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
304
305 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bimap, bimap2);
306 }
307
308 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
309 fn serde_hash_w_hashbrown_hasherrust-analyzer cargo bimap 0.6.3 serde/tests/serde_hash_w_hashbrown_hasher().() {
•310 let hasher_builder = hashbrownrust-analyzer cargo hashbrown 0.17.1 crate/::DefaultHashBuilderrust-analyzer cargo hashbrown 0.17.1 hasher/DefaultHashBuilder#::defaultrust-analyzer cargo hashbrown 0.17.1 hasher/impl#[DefaultHashBuilder][Default]default().();
311 let mut bimap = BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#::<
312 char,
313 u8,
•314 hashbrownrust-analyzer cargo hashbrown 0.17.1 crate/::DefaultHashBuilderrust-analyzer cargo hashbrown 0.17.1 hasher/DefaultHashBuilder#,
315 hashbrownrust-analyzer cargo hashbrown 0.17.1 crate/::DefaultHashBuilderrust-analyzer cargo hashbrown 0.17.1 hasher/DefaultHashBuilder#,
316 >::with_capacity_and_hashersrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]with_capacity_and_hashers().(
317 4, hasher_builder.clonerust-analyzer cargo hashbrown 0.17.1 hasher/impl#[DefaultHashBuilder][Clone]clone().(), hasher_builder.clonerust-analyzer cargo hashbrown 0.17.1 hasher/impl#[DefaultHashBuilder][Clone]clone().()
318 );
319 bimap.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().('x', 1);
320 bimap.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().('y', 2);
321 bimap.insertrust-analyzer cargo bimap 0.6.3 hash/impl#[`BiHashMap<L, R, LS, RS>`]insert().('z', 3);
322
323 let json = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_stringrust-analyzer cargo serde_json 1.0.151 ser/to_string().(&bimap).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
324 let bimap2 = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::from_strrust-analyzer cargo serde_json 1.0.151 de/from_str().(&json).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
325
326 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bimap, bimap2);
327 }
328
329 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
330 fn serde_btreerust-analyzer cargo bimap 0.6.3 serde/tests/serde_btree().() {
331 let mut bimap = BiBTreeMaprust-analyzer cargo bimap 0.6.3 btree/BiBTreeMap#::newrust-analyzer cargo bimap 0.6.3 btree/impl#[`BiBTreeMap<L, R>`]new().();
332 bimap.insertrust-analyzer cargo bimap 0.6.3 btree/impl#[`BiBTreeMap<L, R>`]insert().('a', 1);
333 bimap.insertrust-analyzer cargo bimap 0.6.3 btree/impl#[`BiBTreeMap<L, R>`]insert().('b', 2);
334 bimap.insertrust-analyzer cargo bimap 0.6.3 btree/impl#[`BiBTreeMap<L, R>`]insert().('c', 3);
335
336 let json = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_stringrust-analyzer cargo serde_json 1.0.151 ser/to_string().(&bimap).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
337 let bimap2 = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::from_strrust-analyzer cargo serde_json 1.0.151 de/from_str().(&json).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
338
339 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bimap, bimap2);
340 }
341
342 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
343 fn expecting_btreerust-analyzer cargo bimap 0.6.3 serde/tests/expecting_btree().() {
344 let visitor = BiBTreeMapVisitorrust-analyzer cargo bimap 0.6.3 serde/BiBTreeMapVisitor# {
345 markerrust-analyzer cargo bimap 0.6.3 serde/BiBTreeMapVisitor#marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#::<BiBTreeMaprust-analyzer cargo bimap 0.6.3 btree/BiBTreeMap#<char, i32>>,
346 };
347 let error_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:?}", visitor.visit_boolrust-analyzer cargo serde_core 1.0.229 de/Visitor#visit_bool().::<Errorrust-analyzer cargo serde_core 1.0.229 de/value/Error#>(true));
348 let expected = "Err(Error(\"invalid type: boolean `true`, expected a map\"))";
349 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(error_str, expected);
350 }
351
352 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
353 fn expecting_hashrust-analyzer cargo bimap 0.6.3 serde/tests/expecting_hash().() {
354 let visitor = BiHashMapVisitorrust-analyzer cargo bimap 0.6.3 serde/BiHashMapVisitor# {
355 markerrust-analyzer cargo bimap 0.6.3 serde/BiHashMapVisitor#marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#::<BiHashMaprust-analyzer cargo bimap 0.6.3 hash/BiHashMap#<char, i32>>,
356 };
357 let error_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:?}", visitor.visit_boolrust-analyzer cargo serde_core 1.0.229 de/Visitor#visit_bool().::<Errorrust-analyzer cargo serde_core 1.0.229 de/value/Error#>(true));
358 let expected = "Err(Error(\"invalid type: boolean `true`, expected a map\"))";
359 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(error_str, expected);
360 }
361 }