Skip to main content

PersistentEntity

Trait PersistentEntity 

Source
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§

Source

fn entity_id(&self) -> String

Get the entity’s unique identifier

Source

fn set_entity_id(&mut self, id: String)

Set the entity’s unique identifier

Source

fn created_at(&self) -> Option<DateTime<Utc>>

Get creation timestamp

Source

fn set_created_at(&mut self, ts: DateTime<Utc>)

Set creation timestamp

Source

fn updated_at(&self) -> Option<DateTime<Utc>>

Get last update timestamp

Source

fn set_updated_at(&mut self, ts: DateTime<Utc>)

Set last update timestamp

Source

fn deleted_at(&self) -> Option<DateTime<Utc>>

Get soft delete timestamp (None if not deleted)

Source

fn set_deleted_at(&mut self, ts: Option<DateTime<Utc>>)

Set soft delete timestamp

Provided Methods§

Source

fn is_deleted(&self) -> bool

Check if entity is soft-deleted

Source

fn mark_deleted(&mut self)

Mark entity as deleted (soft delete)

Source

fn restore(&mut self)

Restore a soft-deleted entity

Source

fn touch(&mut self)

Touch the entity (update timestamp)

Source

fn generate_id() -> String

Generate a new ID for this entity type

Source

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".

Implementors§