pub trait CommitHook:
Send
+ 'static
+ Sized {
// Provided methods
fn pre_commit(
self,
op: HookOperation<'_>,
) -> impl Future<Output = Result<PreCommitRet<'_, Self>, Error>> + Send { ... }
fn post_commit(self) { ... }
fn merge(&mut self, _other: &mut Self) -> bool { ... }
fn force_execute_pre_commit(
self,
op: &mut impl AtomicOperation,
) -> impl Future<Output = Result<Self, Error>> + Send { ... }
}Expand description
Trait for implementing custom commit hooks that execute before and after transaction commits.
Hooks execute in order: pre_commit() → database commit → post_commit().
Multiple hooks of the same type can be merged via merge().
See module-level documentation for a complete example.
Provided Methods§
Sourcefn pre_commit(
self,
op: HookOperation<'_>,
) -> impl Future<Output = Result<PreCommitRet<'_, Self>, Error>> + Send
fn pre_commit( self, op: HookOperation<'_>, ) -> impl Future<Output = Result<PreCommitRet<'_, Self>, Error>> + Send
Called before the transaction commits. Can perform database operations.
Errors returned here will roll back the transaction.
Sourcefn post_commit(self)
fn post_commit(self)
Called after successful commit. Cannot fail, not async.
Sourcefn merge(&mut self, _other: &mut Self) -> bool
fn merge(&mut self, _other: &mut Self) -> bool
Try to merge another hook of the same type into this one.
Returns true if merged (other will be dropped), false if not (both execute separately).
Sourcefn force_execute_pre_commit(
self,
op: &mut impl AtomicOperation,
) -> impl Future<Output = Result<Self, Error>> + Send
fn force_execute_pre_commit( self, op: &mut impl AtomicOperation, ) -> impl Future<Output = Result<Self, Error>> + Send
Execute the hook immediately, bypassing the hook system.
Useful when AtomicOperation::add_commit_hook() returns Err(hook).
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.