Skip to main content

Module hooks

Module hooks 

Source
Expand description

Lifecycle hooks attached to a Table.

Register them with Table::with_hook / Table::add_hook. Before-write hooks run ahead of set-invariant enforcement, ordered by Phase; the firing itself lives in the table::sets write paths.

Structs§

AfterCx
What an after-commit hook receives. record is the committed row (the former contents for a delete); before is the row as it was before an update, and None for inserts and deletes.
BeforeCx
What a before-write hook receives: the record about to be written (mutable), the write’s WriteContext if one is in scope, and the entity-erased table.
DeleteAllCx
What a bulk-delete hook receives: the table whose whole set is being deleted. Its conditions() describe the set.
DeleteCx
What a before-delete hook receives: the row id and its current contents.
Hooks
A table’s registered lifecycle hooks, split by placement. The before-write bands are kept ordered by Phase. Populated via Table::with_hook.
SelectCx
What a read hook receives: the table about to be read (its conditions describe the set) and the WriteContext in scope, if any — the same task-local a write sees, so one scope covers a request’s reads and writes.

Enums§

Hook
A lifecycle hook attached to a table via Table::with_hook. Each variant carries a closure receiving exactly the references available at that stage. BeforeSave/AfterSave are sugar that register for both insert and update.
HookReturn
What a before_delete hook decided.
Phase
Ordering band for before-write hooks. Hooks run in this order (and in registration order within a band), ahead of set-invariant enforcement.

Functions§

after_hook
Build an AfterFn from a closure.
before_delete_hook
Build a BeforeDeleteFn from a closure.
before_delete_hook_sync
Build a BeforeDeleteFn from a synchronous closure over the row id and the write’s context: Ok proceeds with the delete, an Err vetoes it.
before_hook
Build a BeforeFn from a closure; the bound guides closure inference.
before_hook_sync
Build a BeforeFn from a synchronous closure over the record and the write’s context; an Err cancels the write. For callers with nothing to await, such as a script evaluated in place.
before_hook_sync_cx
Build a BeforeFn from a synchronous closure over the whole BeforeCx: the record, and on an update the id and the stored row.
delete_all_hook
Build a DeleteAllFn from a closure.
select_hook
Build a SelectFn from a closure.

Type Aliases§

AfterFn
An after-commit hook: side-effects on the committed row. Used for inserts, updates, and deletes.
BeforeDeleteFn
A before-delete hook: may Err to veto, or return HookReturn::Handled to take over (soft-delete).
BeforeFn
A before-write hook: mutate the record in place ahead of invariant enforcement, returning Err to cancel the write.
BoxFuture
The future a hook returns.
DeleteAllFn
A bulk-delete hook, before (an Err cancels) or after delete_all.
SelectFn
A read hook: an Err refuses the read.