serde_dynamo/ser/
serializer_tuple_variant.rs1use super::{AttributeValue, Error, Result, Serializer};
2use serde_core::{ser, Serialize};
3use std::collections::HashMap;
4
5pub struct SerializerTupleVariant {
6 key: &'static str,
7 vec: Vec<AttributeValue>,
8}
9
10impl SerializerTupleVariant {
11 pub fn new(key: &'static str, len: usize) -> Self {
12 Self {
13 key,
14 vec: Vec::with_capacity(len),
15 }
16 }
17}
18
19impl ser::SerializeTupleVariant for SerializerTupleVariant {
20 type Ok = AttributeValue;
21 type Error = Error;
22
23 fn serialize_field<F>(&mut self, value: &F) -> Result<(), Self::Error>
24 where
25 F: ?Sized,
26 F: Serialize,
27 {
28 let serializer = Serializer;
29 let value = value.serialize(serializer)?;
30 self.vec.push(value);
31 Ok(())
32 }
33
34 fn end(self) -> Result<Self::Ok, Self::Error> {
35 let mut hashmap = HashMap::with_capacity(1);
36 hashmap.insert(self.key.to_string(), AttributeValue::L(self.vec));
37
38 Ok(AttributeValue::M(hashmap))
39 }
40}