/rust/registry/src/index.crates.io-6f17d22bba15001f/serde-content-0.1.2/src/ser/map.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::ser::Value; |
2 | | use crate::Error; |
3 | | use crate::Serializer; |
4 | | use alloc::vec::Vec; |
5 | | use serde::ser; |
6 | | |
7 | | pub struct Map<'a> { |
8 | | vec: Vec<(Value<'a>, Value<'a>)>, |
9 | | human_readable: bool, |
10 | | } |
11 | | |
12 | | impl<'a> Map<'a> { |
13 | 0 | pub(super) const fn new(vec: Vec<(Value<'a>, Value<'a>)>, human_readable: bool) -> Self { |
14 | 0 | Self { |
15 | 0 | vec, |
16 | 0 | human_readable, |
17 | 0 | } |
18 | 0 | } |
19 | | } |
20 | | |
21 | | impl<'a> ser::SerializeMap for Map<'a> { |
22 | | type Ok = Value<'a>; |
23 | | type Error = Error; |
24 | | |
25 | 0 | fn serialize_key<T>(&mut self, key: &T) -> Result<(), Error> |
26 | 0 | where |
27 | 0 | T: ?Sized + ser::Serialize, |
28 | 0 | { |
29 | 0 | let key = key.serialize(Serializer::with_human_readable(self.human_readable))?; |
30 | 0 | self.vec.push((key, Value::Unit)); |
31 | 0 | Ok(()) |
32 | 0 | } |
33 | | |
34 | 0 | fn serialize_value<T>(&mut self, value: &T) -> Result<(), Error> |
35 | 0 | where |
36 | 0 | T: ?Sized + ser::Serialize, |
37 | 0 | { |
38 | 0 | if let Some(last) = self.vec.last_mut() { |
39 | 0 | last.1 = value.serialize(Serializer::with_human_readable(self.human_readable))?; |
40 | 0 | } |
41 | 0 | Ok(()) |
42 | 0 | } |
43 | | |
44 | 0 | fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), Self::Error> |
45 | 0 | where |
46 | 0 | K: ?Sized + ser::Serialize, |
47 | 0 | V: ?Sized + ser::Serialize, |
48 | 0 | { |
49 | 0 | let serializer = Serializer::with_human_readable(self.human_readable); |
50 | 0 | let key = key.serialize(serializer)?; |
51 | 0 | let value = value.serialize(serializer)?; |
52 | 0 | self.vec.push((key, value)); |
53 | 0 | Ok(()) |
54 | 0 | } Unexecuted instantiation: <serde_content::ser::map::Map as serde::ser::SerializeMap>::serialize_entry::<alloc::string::String, surrealdb_core::sql::value::value::Value> Unexecuted instantiation: <serde_content::ser::map::Map as serde::ser::SerializeMap>::serialize_entry::<&alloc::string::String, &surrealdb_core::sql::kind::Kind> Unexecuted instantiation: <serde_content::ser::map::Map as serde::ser::SerializeMap>::serialize_entry::<_, _> |
55 | | |
56 | 0 | fn end(self) -> Result<Self::Ok, Error> { |
57 | 0 | Ok(Value::Map(self.vec)) |
58 | 0 | } |
59 | | } |