Module serde_dynamo::string_set
source · Expand description
Serializer codec for serializing a list of strings as a set
§Usage
To use, annotate the field with #[serde(with = "serde_dynamo::string_set")]
.
DynamoDB will return an error if given an empty set. Thus, it may
be beneficial to additionally annotate the field with #[serde(default)]
and #[serde(skip_serializing_if = "<empty check>")]
. This will make sure
that the field is omitted when empty.
This serializer does not check for duplicate values or an empty set. If the set contains duplicate values or is empty, DynamoDB will return a validation error when the attribute value is used.
§Errors
The serializer in this module will return an error if:
- the value does not serialize as a sequence
- the sequence contains any value that is not a string
§Examples
use serde_derive::{Serialize, Deserialize};
use serde_dynamo::{Item, AttributeValue};
#[derive(Serialize, Deserialize)]
struct MyStruct {
#[serde(with = "serde_dynamo::string_set")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
names: Vec<String>,
}
let my_struct = MyStruct {
names: vec!["John".to_string(), "Jane".to_string()],
};
let serialized: Item = serde_dynamo::to_item(&my_struct).unwrap();
assert_eq!(
serialized["names"],
AttributeValue::Ss(vec!["John".to_string(), "Jane".to_string()])
);
Structs§
- Serializes the wrapped value as a string set
Functions§
- Deserializes the given value as a set
- Serializes the given value as a string set