Trait Model

Source
pub trait Model:
    Send
    + Sync
    + Clone
    + Debug {
    type PrimaryKey: Send + Sync + Clone + Debug;

    // Required methods
    fn table_name() -> &'static str;
    fn get_key(&self) -> Option<Self::PrimaryKey>;
    fn set_key(&mut self, key: Self::PrimaryKey);

    // Provided methods
    fn primary_key() -> &'static str { ... }
    fn fillable() -> Vec<&'static str> { ... }
    fn guarded() -> Vec<&'static str> { ... }
    fn hidden() -> Vec<&'static str> { ... }
    fn visible() -> Vec<&'static str> { ... }
    fn validate(&self) -> Result<()> { ... }
}
Expand description

Trait for data models

Required Associated Types§

Source

type PrimaryKey: Send + Sync + Clone + Debug

Primary key type

Required Methods§

Source

fn table_name() -> &'static str

Returns the table name

Source

fn get_key(&self) -> Option<Self::PrimaryKey>

Gets the primary key value

Source

fn set_key(&mut self, key: Self::PrimaryKey)

Sets the primary key value

Provided Methods§

Source

fn primary_key() -> &'static str

Returns the primary key field name

Source

fn fillable() -> Vec<&'static str>

Returns fillable fields

Source

fn guarded() -> Vec<&'static str>

Returns guarded fields

Source

fn hidden() -> Vec<&'static str>

Returns hidden fields (won’t be serialized)

Source

fn visible() -> Vec<&'static str>

Returns visible fields (will be serialized)

Source

fn validate(&self) -> Result<()>

Validates the model

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§