Skip to main content

HasConstAttribute

Trait HasConstAttribute 

Source
pub trait HasConstAttribute<A: AttributeDefinition> {
    type Value: IntoTypedAttributeValue<A::Type>;

    const VALUE: Self::Value;
}
Expand description

Links an item type to a compile-time constant DynamoDB attribute value.

Implementing this trait for a pair (Item, Attr) declares that every instance of Item has the same fixed value for attribute Attr. This is the common case for type discriminators (e.g. ItemType always "USER").

Every type that implements HasConstAttribute<A> automatically gets a blanket HasAttribute<A> implementation that returns VALUE regardless of the instance.

Implementations are generated by dynamodb_item! and has_attributes!.

§Examples

use dynamodb_facade::{HasAttribute, HasConstAttribute, NoId};

// PlatformConfig has a constant PK value.
assert_eq!(<PlatformConfig as HasConstAttribute<PK>>::VALUE, "PLATFORM_CONFIG");
// Also returned by the blanket HasAttribute<PK> implementation
assert_eq!(<PlatformConfig as HasAttribute<PK>>::attribute_value(NoId), "PLATFORM_CONFIG");

// User has a constant SK value.
assert_eq!(<User as HasConstAttribute<SK>>::VALUE, "USER");

Required Associated Constants§

Source

const VALUE: Self::Value

The constant Rust value shared by all instances of this item type, later converted to the DynamoDB attribute value by the library.

Required Associated Types§

Source

type Value: IntoTypedAttributeValue<A::Type>

A Rust constant type convertible to the DynamoDB attribute value for this attribute.

Bounded by IntoTypedAttributeValue<A::Type>, which guarantees that when this Rust value is converted to an AttributeValue it will produce the correct DynamoDB scalar type (S for StringAttribute, N for NumberAttribute, B for BinaryAttribute).

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 HasConstAttribute<ItemType> for Enrollment

Source§

const VALUE: Self::Value = "ENROLLMENT"

Source§

type Value = &'static str

Source§

impl HasConstAttribute<ItemType> for PlatformConfig

Source§

const VALUE: Self::Value = "PLATFORM_CONFIG"

Source§

type Value = &'static str

Source§

impl HasConstAttribute<ItemType> for User

Source§

const VALUE: Self::Value = "USER"

Source§

type Value = &'static str

Source§

impl HasConstAttribute<PK> for PlatformConfig

Source§

const VALUE: Self::Value = "PLATFORM_CONFIG"

Source§

type Value = &'static str

Source§

impl HasConstAttribute<SK> for PlatformConfig

Source§

const VALUE: Self::Value = "PLATFORM_CONFIG"

Source§

type Value = &'static str

Source§

impl HasConstAttribute<SK> for User

Source§

const VALUE: Self::Value = "USER"

Source§

type Value = &'static str