pub struct HookDispatcher;Expand description
钩子执行辅助工具
封装常见的钩子触发顺序,避免业务代码手动逐个调用。
Implementations§
Source§impl HookDispatcher
impl HookDispatcher
Sourcepub fn insert<M, F>(
ctx: &mut HookContext,
f: F,
) -> Result<<M as Model>::PrimaryKey, DbError>
pub fn insert<M, F>( ctx: &mut HookContext, f: F, ) -> Result<<M as Model>::PrimaryKey, DbError>
INSERT 操作的完整钩子序列:
before_write → before_save → before_validate → validate → after_validate
→ before_insert → (执行) → after_insert → after_save → after_write
f 为执行实际 INSERT 操作的闭包,返回插入后的主键。
Sourcepub fn update<M, F>(
ctx: &mut HookContext,
id: &<M as Model>::PrimaryKey,
f: F,
) -> Result<(), DbError>
pub fn update<M, F>( ctx: &mut HookContext, id: &<M as Model>::PrimaryKey, f: F, ) -> Result<(), DbError>
UPDATE 操作的完整钩子序列(同 INSERT,含 validate)
Sourcepub fn delete<M, F>(
ctx: &mut HookContext,
id: &<M as Model>::PrimaryKey,
f: F,
) -> Result<(), DbError>
pub fn delete<M, F>( ctx: &mut HookContext, id: &<M as Model>::PrimaryKey, f: F, ) -> Result<(), DbError>
DELETE 操作的完整钩子序列
Sourcepub fn restore<M, F>(
ctx: &mut HookContext,
id: &<M as Model>::PrimaryKey,
f: F,
) -> Result<(), DbError>
pub fn restore<M, F>( ctx: &mut HookContext, id: &<M as Model>::PrimaryKey, f: F, ) -> Result<(), DbError>
RESTORE 操作(软删除恢复)的完整钩子序列
Sourcepub fn find<M, F>(
ctx: &mut HookContext,
id: &<M as Model>::PrimaryKey,
f: F,
) -> Result<(), DbError>
pub fn find<M, F>( ctx: &mut HookContext, id: &<M as Model>::PrimaryKey, f: F, ) -> Result<(), DbError>
FIND 操作(单行查询)的完整钩子序列:
before_find → (执行 SELECT) → after_find
f 为执行实际 SELECT 操作的闭包,返回查询到的实例。
Auto Trait Implementations§
impl Freeze for HookDispatcher
impl RefUnwindSafe for HookDispatcher
impl Send for HookDispatcher
impl Sync for HookDispatcher
impl Unpin for HookDispatcher
impl UnsafeUnpin for HookDispatcher
impl UnwindSafe for HookDispatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.