Skip to main content

Model

Trait Model 

Source
pub trait Model:
    Sized
    + Default
    + Send
    + Sync {
    type Key: FromValue + Into<Value> + Clone + Send + Sync + Debug;

    const TABLE: &'static str;
    const PRIMARY_KEY: &'static str;
    const COLUMNS: &'static str;

    // Required methods
    fn from_row(row: &Row) -> Result<Self>;
    fn key(&self) -> Self::Key;
    fn set_key(&mut self, key: Self::Key);
    fn values(&self) -> Vec<(&'static str, Value)>;
}
Expand description

Implemented by #[derive(Model)]; not written by hand.

Required Associated Constants§

Source

const TABLE: &'static str

Source

const PRIMARY_KEY: &'static str

Source

const COLUMNS: &'static str

The selectable columns, already quoted: "id", "name".

Required Associated Types§

Source

type Key: FromValue + Into<Value> + Clone + Send + Sync + Debug

The primary key’s type — usually i64.

Required Methods§

Source

fn from_row(row: &Row) -> Result<Self>

Source

fn key(&self) -> Self::Key

Source

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

Source

fn values(&self) -> Vec<(&'static str, Value)>

The columns written on insert and update — everything except the primary key and the timestamps the database maintains.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§