pub enum HookAction {
Continue,
Modify(Vec<u8>),
Stop,
Error(String),
}Expand description
钩子执行后返回的动作指令
当一个钩子执行完毕后,它返回一个 HookAction 来告诉系统如何继续处理。
系统会按照以下优先级处理:
- 如果任何
before_*钩子返回Stop,整个操作被阻止 - 如果任何
before_*钩子返回Error,整个操作失败 - 只有所有
before_*钩子都返回Continue或Modify时,操作才会继续
§变体说明
-
Continue: 继续执行,不修改数据。这是大多数钩子的默认返回值。 -
Modify(data): 继续执行,但使用修改后的数据。 只有before_store和after_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
impl HookAction
Sourcepub fn should_continue(&self) -> bool
pub fn should_continue(&self) -> bool
判断是否应该继续执行
注意:Modify 也会继续执行,只是会携带修改后的数据
Sourcepub fn has_modified_data(&self) -> bool
pub fn has_modified_data(&self) -> bool
判断是否携带了修改后的数据
Sourcepub fn get_modified_data(self) -> Option<Vec<u8>>
pub fn get_modified_data(self) -> Option<Vec<u8>>
获取修改后的数据(如果有)
Trait Implementations§
Source§impl Clone for HookAction
impl Clone for HookAction
Source§fn clone(&self) -> HookAction
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HookAction
impl RefUnwindSafe for HookAction
impl Send for HookAction
impl Sync for HookAction
impl Unpin for HookAction
impl UnsafeUnpin for HookAction
impl UnwindSafe for HookAction
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more