Debian Codegraph @

src/map/serde_seq.rs

raw symbols SCIP
1 //! Functions to serialize and deserialize an [`OrderMap`] as an ordered sequence.
2 //!
3 //! The default `serde` implementation serializes `OrderMap` as a normal map,
4 //! but there is no guarantee that serialization formats will preserve the order
5 //! of the key-value pairs. This module serializes `OrderMap` as a sequence of
6 //! `(key, value)` elements instead, in order.
7 //!
8 //! This module may be used in a field attribute for derived implementations:
9 //!
10 //! ```
11 //! # use ordermap::OrderMap;
12 //! # use serde::{Deserialize, Serialize};
13 //! #[derive(Deserialize, Serialize)]
14 //! struct Data {
15 //! #[serde(with = "ordermap::map::serde_seq")]
16 //! map: OrderMap<i32, u64>,
17 //! // ...
18 //! }
19 //! ```
20
21 use craterust-analyzer cargo ordermap 1.2.0 crate/::OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap#;
22 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core 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#};
23 use indexmaprust-analyzer cargo indexmap 2.14.0 crate/::maprust-analyzer cargo indexmap 2.14.0 map/::serde_seqrust-analyzer cargo indexmap 2.14.0 map/serde_seq/ as ixrust-analyzer cargo indexmap 2.14.0 map/serde_seq/;
24 use serde_corerust-analyzer cargo serde_core 1.0.228 crate/::derust-analyzer cargo serde_core 1.0.228 de/::{Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#, Deserializerrust-analyzer cargo serde_core 1.0.228 de/Deserializer#};
25 use serde_corerust-analyzer cargo serde_core 1.0.228 crate/::serrust-analyzer cargo serde_core 1.0.228 ser/::{Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#, Serializerrust-analyzer cargo serde_core 1.0.228 ser/Serializer#};
26
27 /// Serializes an [`OrderMap`] as an ordered sequence.
28 ///
29 /// This function may be used in a field attribute for deriving [`Serialize`]:
30 ///
31 /// ```
32 /// # use ordermap::OrderMap;
33 /// # use serde::Serialize;
34 /// #[derive(Serialize)]
35 /// struct Data {
36 /// #[serde(serialize_with = "ordermap::map::serde_seq::serialize")]
37 /// map: OrderMap<i32, u64>,
38 /// // ...
39 /// }
40 /// ```
41 pub fn serializerust-analyzer cargo ordermap 1.2.0 map/serde_seq/serialize().<K, V, S, T>(map: &OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap#<K, V, S>, serializer: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T::Okrust-analyzer cargo serde_core 1.0.228 ser/Serializer#Ok#, T::Errorrust-analyzer cargo serde_core 1.0.228 ser/Serializer#Error#>
42 where
43 K: Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#,
44 V: Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#,
45 T: Serializerrust-analyzer cargo serde_core 1.0.228 ser/Serializer#,
46 {
47 ixrust-analyzer cargo indexmap 2.14.0 map/serde_seq/::serializerust-analyzer cargo indexmap 2.14.0 map/serde_seq/serialize().(&map.innerrust-analyzer cargo ordermap 1.2.0 map/OrderMap#inner., serializer)
48 }
49
50 /// Deserializes an [`OrderMap`] from an ordered sequence.
51 ///
52 /// This function may be used in a field attribute for deriving [`Deserialize`]:
53 ///
54 /// ```
55 /// # use ordermap::OrderMap;
56 /// # use serde::Deserialize;
57 /// #[derive(Deserialize)]
58 /// struct Data {
59 /// #[serde(deserialize_with = "ordermap::map::serde_seq::deserialize")]
60 /// map: OrderMap<i32, u64>,
61 /// // ...
62 /// }
63 /// ```
64 pub fn deserializerust-analyzer cargo ordermap 1.2.0 map/serde_seq/deserialize().<'de, D, K, V, S>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap#<K, V, S>, D::Errorrust-analyzer cargo serde_core 1.0.228 de/Deserializer#Error#>
65 where
66 D: Deserializerrust-analyzer cargo serde_core 1.0.228 de/Deserializer#<'de>,
67 K: Deserializerust-analyzer cargo serde_core 1.0.228 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#,
68 V: Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#<'de>,
69 S: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# + BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
70 {
71 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap# {
72 innerrust-analyzer cargo ordermap 1.2.0 map/OrderMap#inner.: ixrust-analyzer cargo indexmap 2.14.0 map/serde_seq/::deserializerust-analyzer cargo indexmap 2.14.0 map/serde_seq/deserialize().(deserializer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
73 })
74 }