Skip to main content

Model

Trait Model 

Source
pub trait Model:
    Sized
    + for<'r> FromRow<'r, AnyRow>
    + Send
    + Unpin
    + 'static {
    type New: Send;

    const TABLE: &'static str;
    const SOFT_DELETE_COLUMN: Option<&'static str> = None;

    // Required method
    fn create(
        data: Self::New,
    ) -> impl Future<Output = Result<Self, AppError>> + Send;
}
Expand description

Implemented automatically by #[derive(Model)].

-> impl Future<...> + Send rather than a plain async fn, matching larust_repository::Repository’s own established reasoning: trait async fn doesn’t propagate Send by default, and this needs to be callable from axum handlers (and from generic code reached by them) that require Send futures. The generated impl can still be written as an ordinary async fn - its desugared return type already satisfies -> impl Future<...>.

Required Associated Constants§

Source

const TABLE: &'static str

Mirrors the inherent Self::TABLE constant #[derive(Model)] already generates.

Provided Associated Constants§

Source

const SOFT_DELETE_COLUMN: Option<&'static str> = None

Some(column) only for a struct marked #[soft_deletes] - the nullable timestamp column delete() sets instead of actually removing a row. Defaults to None so every other model needs no changes at all; only the soft-delete-aware code paths (QueryBuilder’s own filtering, belongs_to_many’s generated JOIN) ever read this, always at runtime through the real, monomorphized const for whatever concrete type is in play - never something a macro invocation elsewhere could see at expansion time, since it has no visibility into a different struct’s own #[derive(Model)] attributes.

Required Associated Types§

Source

type New: Send

The struct’s own generated New{Model} type (every field except the primary key).

Required Methods§

Source

fn create( data: Self::New, ) -> impl Future<Output = Result<Self, AppError>> + Send

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§