Skip to main content

attribute_definitions

Macro attribute_definitions 

Source
macro_rules! attribute_definitions {
    {
        $(
            $(#[$meta:meta])*
            $tname:ident {
                $name:literal: $t:ty
            }
        )+
    } => { ... };
    ($($tt:tt)*) => { ... };
}
Expand description

Declares one or more DynamoDB attribute definitions as zero-sized types.

Each invocation generates a pub struct that implements AttributeDefinition, providing a compile-time const NAME: &str and an associated type Type (one of StringAttribute, NumberAttribute, or BinaryAttribute).

These zero-sized types serve as type-level identifiers throughout the library: they are used as generic parameters in HasAttribute, HasConstAttribute, KeySchema, and IndexDefinition.

§Syntax

attribute_definitions! {
    [doc comments and attributes]
    TypeName { "dynamo_attribute_name": AttributeTypeMarker }
    ...
}

Multiple definitions can appear in a single invocation.

§Examples

use dynamodb_facade::{attribute_definitions, StringAttribute, NumberAttribute};

attribute_definitions! {
    /// Partition key for the platform mono-table.
    PK { "PK": StringAttribute }

    /// Sort key for the platform mono-table.
    SK { "SK": StringAttribute }

    /// Item type discriminator (single-table design).
    ItemType { "_TYPE": StringAttribute }

    /// TTL attribute for expiring items.
    Expiration { "expiration_timestamp": NumberAttribute }

    /// Email attribute, used as a GSI partition key.
    Email { "email": StringAttribute }
}

use dynamodb_facade::AttributeDefinition;
// Each generated type exposes its DynamoDB attribute name as a constant.
assert_eq!(PK::NAME, "PK");
assert_eq!(SK::NAME, "SK");
assert_eq!(ItemType::NAME, "_TYPE");
assert_eq!(Expiration::NAME, "expiration_timestamp");
assert_eq!(Email::NAME, "email");