[][src]Trait mdl::model::Model

pub trait Model: Serialize + DeserializeOwned {
    fn key(&self) -> String;

    fn db() -> &'static str { ... }
fn tob(&self) -> Result<Vec<u8>, Error> { ... }
fn fromb(data: &[u8]) -> Result<Self, Error> { ... }
fn store<S: Store>(&self, store: &S) -> Result<(), Error> { ... }
fn store_sig<S: Store, G: Signaler>(
        &self,
        store: &S,
        sig: &G
    ) -> Result<(), Error> { ... }
fn delete<S: Store>(&self, store: &S) -> Result<(), Error> { ... }
fn delete_sig<S: Store, G: Signaler>(
        &self,
        store: &S,
        sig: &G
    ) -> Result<(), Error> { ... }
fn get<S: Store>(store: &S, key: &str) -> Result<Self, Error> { ... }
fn all<S: Store>(store: &S, prefix: &str) -> Result<Vec<Self>, Error> { ... }
fn iter<S, F>(store: &S, prefix: &str, f: F) -> Result<(), Error>
    where
        S: Store,
        F: Fn(Self) -> Continue
, { ... } }

Trait to implement Cacheable data Model

Required methods

fn key(&self) -> String

key to identify the data object, this should be unique

Loading content...

Provided methods

fn db() -> &'static str

database name, where to store instances of this struct

fn tob(&self) -> Result<Vec<u8>, Error>

Data Struct serialization

fn fromb(data: &[u8]) -> Result<Self, Error>

Data Struct deserialization

fn store<S: Store>(&self, store: &S) -> Result<(), Error>

Persist the struct in the database

fn store_sig<S: Store, G: Signaler>(
    &self,
    store: &S,
    sig: &G
) -> Result<(), Error>

Persist the struct in the database and emit the signal to the signaler

fn delete<S: Store>(&self, store: &S) -> Result<(), Error>

Deletes the object from the database

fn delete_sig<S: Store, G: Signaler>(
    &self,
    store: &S,
    sig: &G
) -> Result<(), Error>

Deletes the object from the database and emit the signal to the signaler

fn get<S: Store>(store: &S, key: &str) -> Result<Self, Error>

Loads the struct from the database

fn all<S: Store>(store: &S, prefix: &str) -> Result<Vec<Self>, Error>

Get all objects with this prefix

fn iter<S, F>(store: &S, prefix: &str, f: F) -> Result<(), Error> where
    S: Store,
    F: Fn(Self) -> Continue

Iterate over all objects with this prefix

Loading content...

Implementors

Loading content...