pub trait PersistentEntity:
Clone
+ Send
+ Sync
+ Debug
+ Serialize
+ DeserializeOwned
+ 'static {
Show 16 methods
// Required methods
fn entity_id(&self) -> String;
fn set_entity_id(&mut self, id: String);
fn created_at(&self) -> Option<DateTime<Utc>>;
fn set_created_at(&mut self, ts: DateTime<Utc>);
fn updated_at(&self) -> Option<DateTime<Utc>>;
fn set_updated_at(&mut self, ts: DateTime<Utc>);
fn deleted_at(&self) -> Option<DateTime<Utc>>;
fn set_deleted_at(&mut self, ts: Option<DateTime<Utc>>);
// Provided methods
fn is_deleted(&self) -> bool { ... }
fn mark_deleted(&mut self) { ... }
fn restore(&mut self) { ... }
fn touch(&mut self) { ... }
fn generate_id() -> String { ... }
fn write_protected_fields() -> &'static [&'static str] { ... }
fn state_fields() -> &'static [&'static str] { ... }
fn references() -> &'static [Reference] { ... }
}Expand description
Trait for entities that can be persisted.
This trait defines the common fields and behavior required by all entities that can be stored and retrieved from a repository.
Required Methods§
Sourcefn set_entity_id(&mut self, id: String)
fn set_entity_id(&mut self, id: String)
Set the entity’s unique identifier
Sourcefn created_at(&self) -> Option<DateTime<Utc>>
fn created_at(&self) -> Option<DateTime<Utc>>
Get creation timestamp
Sourcefn set_created_at(&mut self, ts: DateTime<Utc>)
fn set_created_at(&mut self, ts: DateTime<Utc>)
Set creation timestamp
Sourcefn updated_at(&self) -> Option<DateTime<Utc>>
fn updated_at(&self) -> Option<DateTime<Utc>>
Get last update timestamp
Sourcefn set_updated_at(&mut self, ts: DateTime<Utc>)
fn set_updated_at(&mut self, ts: DateTime<Utc>)
Set last update timestamp
Sourcefn deleted_at(&self) -> Option<DateTime<Utc>>
fn deleted_at(&self) -> Option<DateTime<Utc>>
Get soft delete timestamp (None if not deleted)
Sourcefn set_deleted_at(&mut self, ts: Option<DateTime<Utc>>)
fn set_deleted_at(&mut self, ts: Option<DateTime<Utc>>)
Set soft delete timestamp
Provided Methods§
Sourcefn is_deleted(&self) -> bool
fn is_deleted(&self) -> bool
Check if entity is soft-deleted
Sourcefn mark_deleted(&mut self)
fn mark_deleted(&mut self)
Mark entity as deleted (soft delete)
Sourcefn generate_id() -> String
fn generate_id() -> String
Generate a new ID for this entity type
Sourcefn write_protected_fields() -> &'static [&'static str]
fn write_protected_fields() -> &'static [&'static str]
Fields that a generic write (PUT, PATCH and their bulk forms) may not change, by their serialized name.
The generic service refuses a write that would give one of these a new
value, and still accepts a write that carries the stored value
unchanged, so a form that sends the whole record keeps working. Code
that owns the field — a verb, a write service — changes it through its
own path. id and metadata are refused for every entity regardless
of this list. The schema generator fills it from the fields the schema
declares as not freely writable; the default protects nothing more.
Sourcefn state_fields() -> &'static [&'static str]
fn state_fields() -> &'static [&'static str]
Fields a state machine owns, by their serialized name: they move only through the machine’s verbs.
A state field is usually also in Self::write_protected_fields, which refuses it to
every generic write. A verb’s own write (one running inside
as_transition) may still move these fields — and
only these: every other protected field stays refused inside a transition too. The
schema generator fills it from the entity’s state machines; the default is none, which
leaves a protected state field refused to verbs as well.
Sourcefn references() -> &'static [Reference]
fn references() -> &'static [Reference]
The foreign keys this entity’s fields hold.
Before a generic create, PUT, PATCH or bulk write stores a value in one of these
fields (a create, or a write that changes it), the generic service asks the
repository whether the row it names is visible to the caller, on the request’s own
connection and scope (CrudRepository::reference_visible). A row the caller
cannot see — missing, or fenced off by row-level security — refuses the write with
a reference_missing violation on the field, the same answer a missing row gets, so
the refusal never tells that the row exists elsewhere. The schema generator fills it
from the entity’s relations as a const slice; the default checks nothing beyond
the database’s key.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".