Trait Observer

Source
pub trait Observer<M> {
    // Provided methods
    async fn created(model: &mut Model<'_, M>) -> MongodbResult<()> { ... }
    async fn updated(model: &mut Model<'_, M>) -> MongodbResult<()> { ... }
    async fn deleted(model: &mut Model<'_, M>) -> MongodbResult<()> { ... }
}
Expand description

This trait implement by default for Model but if user wants to override and use it must tell to Model macro

#[Model(coll_name = "users", observer)]
#[derive(Serialize, Deserialize, Debug, Default)]
struct User {
   name: String,
}

Provided Methods§

Source

async fn created(model: &mut Model<'_, M>) -> MongodbResult<()>

this call when document is created , in these observers can’t call save again

Source

async fn updated(model: &mut Model<'_, M>) -> MongodbResult<()>

this call when document is updated it just called when user uses save method not update method

Source

async fn deleted(model: &mut Model<'_, M>) -> MongodbResult<()>

this call when document is delete

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§