pub trait EntityDef {
const ENTITY_TYPE: &'static EntityTypeNameRef;
const PROJECTED_ATTRIBUTES: &'static [&'static str] = _;
}Expand description
The name and attribute definition for an Entity
This trait is used to define the structure of an entity type in a DynamoDB table and how the entity may be queried.
This trait can be implemented manually, but may be better implemented
using the EntityDef derive macro exposed when
using the derive feature on this crate. Manual implementation may
lead to the projected attributes going out of sync with the
entity’s attributes.
§Example
use modyne::EntityDef;
#[derive(EntityDef)]
#[serde(rename = "orange", rename_all = "kebab-case")]
struct MyStruct {
field_1: u32,
#[serde(rename = "second-field")]
field_2: u32,
}The above is equivalent to the following manual definition:
use modyne::{EntityDef, EntityTypeNameRef};
struct MyStruct {
field_1: u32,
field_2: u32,
}
impl EntityDef for MyStruct {
const ENTITY_TYPE: &'static EntityTypeNameRef =
EntityTypeNameRef::from_static("orange");
const PROJECTED_ATTRIBUTES: &'static [&'static str] = &[
"field_1",
"second-field",
];
}If a field is marked with serde’s flatten modifier, then the projected
attributes array will be empty due to the inability of the derive macro
to inspect the fields that are available on the flattened type.
Required Associated Constants§
Sourceconst ENTITY_TYPE: &'static EntityTypeNameRef
const ENTITY_TYPE: &'static EntityTypeNameRef
The name of the entity type
This value will be used to set the entity_type attribute on
all items of this entity type in the DynamoDB table and should
be unique across all entity types in the table.
Provided Associated Constants§
Sourceconst PROJECTED_ATTRIBUTES: &'static [&'static str] = _
const PROJECTED_ATTRIBUTES: &'static [&'static str] = _
The set of attributes that are projected into the entity
By default, all attributes, including the index keys, are projected into the entity. This can be overridden to only project the subset of attributes that are needed for the entity’s use cases.
Use of this attribute is optional, but recommended. If not specified, then any aggregate that uses this entity type will return the entire item from DynamoDB, which can lead to unnecessary network and deserialization overhead.
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.