Entity

Trait Entity 

Source
pub trait Entity:
    Clone
    + Send
    + Sync
    + 'static {
    type Service: Send + Sync;

    // Required methods
    fn resource_name() -> &'static str;
    fn resource_name_singular() -> &'static str;
    fn service_from_host(
        host: &Arc<dyn Any + Send + Sync>,
    ) -> Result<Arc<Self::Service>>;
    fn id(&self) -> Uuid;
    fn entity_type(&self) -> &str;
    fn created_at(&self) -> DateTime<Utc>;
    fn updated_at(&self) -> DateTime<Utc>;
    fn deleted_at(&self) -> Option<DateTime<Utc>>;
    fn status(&self) -> &str;

    // Provided methods
    fn is_deleted(&self) -> bool { ... }
    fn is_active(&self) -> bool { ... }
}
Expand description

Base trait for all entities in the system.

This trait provides the fundamental metadata needed for any entity type. All entities have:

  • id: Unique identifier
  • type: Entity type name (e.g., “user”, “product”)
  • created_at: Creation timestamp
  • updated_at: Last modification timestamp
  • deleted_at: Soft deletion timestamp (optional)
  • status: Current status of the entity

Required Associated Types§

Source

type Service: Send + Sync

The service type that handles operations for this entity

Required Methods§

Source

fn resource_name() -> &'static str

The plural resource name used in URLs (e.g., “users”, “companies”)

Source

fn resource_name_singular() -> &'static str

The singular resource name (e.g., “user”, “company”)

Source

fn service_from_host( host: &Arc<dyn Any + Send + Sync>, ) -> Result<Arc<Self::Service>>

Extract the service instance from the application host/state

Source

fn id(&self) -> Uuid

Get the unique identifier for this entity instance

Source

fn entity_type(&self) -> &str

Get the entity type name

Source

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

Get the creation timestamp

Source

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

Get the last update timestamp

Source

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

Get the deletion timestamp (soft delete)

Source

fn status(&self) -> &str

Get the entity status

Provided Methods§

Source

fn is_deleted(&self) -> bool

Check if the entity has been soft-deleted

Source

fn is_active(&self) -> bool

Check if the entity is active (status == “active” and not deleted)

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.

Implementors§