Skip to main content

AttributeList

Trait AttributeList 

Source
pub trait AttributeList<TD: TableDefinition, T: HasTableKeyAttributes<TD>>: AttributeListSeal<TD, T> {
    // Required method
    fn get_attributes(source: &T) -> HashMap<String, AttributeValue>;
}
Expand description

A sealed, recursive tuple-list of additional DynamoDB attributes for an item.

This trait is sealed and automatically implemented for right-nested tuples of AttributeDefinition types — for example (ItemType, (Expiration, ())). It is the type-level representation of DynamoDBItem::AdditionalAttributes: the set of attributes that are written to DynamoDB in addition to the primary key attributes and the serialization of the underlying type.

The attr_list! macro builds these nested tuple types conveniently: attr_list![ItemType, Expiration] expands to (ItemType, (Expiration, ())).

§Examples

use dynamodb_facade::{attr_list, AttributeList, DynamoDBItem};

// The AdditionalAttributes type for PlatformConfig is (ItemType, ()).
type ConfigAttrs = <PlatformConfig as DynamoDBItem<PlatformTable>>::AdditionalAttributes;

// AttributeList::get_attributes collects all additional attributes into a HashMap.
let config = sample_config();
let attrs = <ConfigAttrs as AttributeList<PlatformTable, PlatformConfig>>::get_attributes(&config);
// Only 1 additional attribute in this case
assert_eq!(attrs.len(), 1);
// It is "_TYPE" and its value for PlatformConfig is "PLATFORM_CONFIG"
assert!(attrs.get("_TYPE").is_some_and(|v| v.as_s().unwrap() == "PLATFORM_CONFIG"));

Required Methods§

Source

fn get_attributes(source: &T) -> HashMap<String, AttributeValue>

Collects all attributes in this list from source into a HashMap<String, AttributeValue>.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<TD, T, AL> AttributeList<TD, T> for AL
where TD: TableDefinition, T: HasTableKeyAttributes<TD>, AL: AttributeListSeal<TD, T>,