Expand description

Serializer codec for serializing a list of binaries as a set

§Usage

To use, annotate the field with #[serde(with = "serde_dynamo::binary_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 binary

§Examples

use serde_bytes::ByteBuf;
use serde_derive::{Serialize, Deserialize};
use serde_dynamo::{Item, AttributeValue};

#[derive(Serialize, Deserialize)]
struct MyStruct {
    #[serde(with = "serde_dynamo::binary_set")]
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    data: Vec<ByteBuf>,
}

let my_struct = MyStruct {
    data: vec![
        ByteBuf::from(b"hello".to_vec()),
        ByteBuf::from(b"world".to_vec())
    ].into(),
};

let serialized: Item = serde_dynamo::to_item(&my_struct).unwrap();
assert_eq!(
    serialized["data"],
    AttributeValue::Bs(vec![b"hello".to_vec(), b"world".to_vec()])
);

Structs§

  • Serializes the wrapped value as a binary set

Functions§