Skip to main content

CommitHook

Trait CommitHook 

Source
pub trait CommitHook: 'static {
    // Required method
    fn before_commit(
        cx: &Cx,
        change: &PanelChange,
        ex: &mut dyn Executor,
    ) -> impl Future<Output = Result<()>> + Send;
}
Expand description

Work every write of a panel does inside its transaction, whichever of the panel’s resources wrote it: an audit trail no resource can leave out. Panel::before_commit registers it.

It runs on the writes Resource::before_commit runs on, right after that hook, with the same transaction and the same rules: run every statement through ex, and an Err rolls the whole write back and fails the request with the write’s failure toast.

struct Audit;

impl CommitHook for Audit {
    async fn before_commit(
        cx: &Cx,
        change: &PanelChange,
        ex: &mut dyn toasty::Executor,
    ) -> Result<()> {
        for record in change.change().records() {
            toasty::create!(AuditEntry {
                resource: change.label().localize(cx),
                record: record.key().to_string(),
            })
            .exec(&mut *ex)
            .await?;
        }
        Ok(())
    }
}

Required Methods§

Source

fn before_commit( cx: &Cx, change: &PanelChange, ex: &mut dyn Executor, ) -> impl Future<Output = Result<()>> + Send

Work inside the write’s transaction, after the resource’s own Resource::before_commit.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§