pub trait PersistentEntity:
Clone
+ Send
+ Sync
+ Debug
+ Serialize
+ DeserializeOwned
+ 'static {
Show 14 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] { ... }
}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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".