Skip to main content

HookAction

Enum HookAction 

Source
pub enum HookAction {
    Continue,
    Modify(Vec<u8>),
    Stop,
    Error(String),
}
Expand description

钩子执行后返回的动作指令

当一个钩子执行完毕后,它返回一个 HookAction 来告诉系统如何继续处理。 系统会按照以下优先级处理:

  1. 如果任何 before_* 钩子返回 Stop,整个操作被阻止
  2. 如果任何 before_* 钩子返回 Error,整个操作失败
  3. 只有所有 before_* 钩子都返回 ContinueModify 时,操作才会继续

§变体说明

  • Continue: 继续执行,不修改数据。这是大多数钩子的默认返回值。

  • Modify(data): 继续执行,但使用修改后的数据。 只有 before_storeafter_read 支持此变体。 例如:加密钩子在 before_store 返回 Modify(encrypted_data)

  • Stop: 立即停止执行,但不算错误。 例如:缓存钩子发现数据已在缓存中,返回 Stop 避免重复读取

  • Error(err): 立即停止并返回错误。 例如:权限检查发现无权访问时返回此值

Variants§

§

Continue

继续执行下一个钩子或操作

§

Modify(Vec<u8>)

继续执行,但使用修改后的数据 (仅用于 before_store 和 after_read)

§

Stop

立即停止执行(不算错误)

§

Error(String)

立即停止并返回错误

Implementations§

Source§

impl HookAction

Source

pub fn should_continue(&self) -> bool

判断是否应该继续执行

注意:Modify 也会继续执行,只是会携带修改后的数据

Source

pub fn has_modified_data(&self) -> bool

判断是否携带了修改后的数据

Source

pub fn get_modified_data(self) -> Option<Vec<u8>>

获取修改后的数据(如果有)

Trait Implementations§

Source§

impl Clone for HookAction

Source§

fn clone(&self) -> HookAction

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HookAction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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