Skip to main content

HookDispatcher

Struct HookDispatcher 

Source
pub struct HookDispatcher;
Expand description

钩子执行辅助工具

封装常见的钩子触发顺序,避免业务代码手动逐个调用。

Implementations§

Source§

impl HookDispatcher

Source

pub fn insert<M, F>(ctx: &mut HookContext, f: F) -> HookResult<M::PrimaryKey>
where M: Hookable, F: FnOnce(&mut HookContext) -> HookResult<M::PrimaryKey>,

INSERT 操作的完整钩子序列: before_writebefore_savebefore_validatevalidateafter_validatebefore_insert → (执行) → after_insertafter_saveafter_write

f 为执行实际 INSERT 操作的闭包,返回插入后的主键。

Source

pub fn update<M, F>( ctx: &mut HookContext, id: &M::PrimaryKey, f: F, ) -> HookResult<()>
where M: Hookable, F: FnOnce(&mut HookContext) -> HookResult<()>,

UPDATE 操作的完整钩子序列(同 INSERT,含 validate)

Source

pub fn delete<M, F>( ctx: &mut HookContext, id: &M::PrimaryKey, f: F, ) -> HookResult<()>
where M: Hookable, F: FnOnce(&mut HookContext) -> HookResult<()>,

DELETE 操作的完整钩子序列

Source

pub fn restore<M, F>( ctx: &mut HookContext, id: &M::PrimaryKey, f: F, ) -> HookResult<()>
where M: Hookable, F: FnOnce(&mut HookContext) -> HookResult<()>,

RESTORE 操作(软删除恢复)的完整钩子序列

Source

pub fn find<M, F>( ctx: &mut HookContext, id: &M::PrimaryKey, f: F, ) -> HookResult<()>
where M: Hookable, F: FnOnce(&mut HookContext) -> HookResult<()>,

FIND 操作(单行查询)的完整钩子序列: before_find → (执行 SELECT) → after_find

f 为执行实际 SELECT 操作的闭包,返回查询到的实例。

Source

pub fn validate<M>(ctx: &mut HookContext) -> HookResult<()>
where M: Hookable,

仅触发验证钩子序列(不执行实际写入): before_validatevalidateafter_validate

适用于调用方需独立校验数据、不立刻写入的场景。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more