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§
Required Associated Types§
Sourcetype Value: IntoTypedAttributeValue<A::Type>
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.