Skip to main content

HookManager

Struct HookManager 

Source
pub struct HookManager { /* private fields */ }
Expand description

钩子链管理器

负责管理和协调多个下载后处理钩子的执行。 支持按顺序执行钩子链,并根据配置决定遇到错误时的处理策略。

Implementations§

Source§

impl HookManager

Source

pub fn new(config: HookConfig) -> Self

创建新的钩子管理器

§Arguments
  • config - 钩子系统配置选项
Source

pub fn add_hook(&mut self, hook: Box<dyn PostDownloadHook>)

向钩子链添加一个新的钩子

钩子将按照添加的顺序被执行。

§Arguments
  • hook - 要添加的钩子实例(必须实现 PostDownloadHook trait)
Source

pub fn remove_hook(&mut self, name: &str) -> Option<Box<dyn PostDownloadHook>>

按名称移除钩子

§Arguments
  • name - 要移除的钩子名称
§Returns

返回被移除的钩子(如果找到),否则返回 None

Source

pub async fn fire_complete(&self, context: &HookContext) -> Result<Vec<String>>

触发所有钩子的 on_complete 回调

按注册顺序依次调用每个钩子的 on_complete 方法。 根据 config.stop_on_error 决定是否在第一个失败时停止。

§Arguments
  • context - 下载完成的上下文信息
§Returns

返回每个钩子的执行结果描述向量。如果 stop_on_error=true 且某个钩子失败, 返回 Err 包含该错误信息。

Source

pub async fn fire_error( &self, context: &HookContext, error: &str, ) -> Result<Vec<String>>

触发所有钩子的 on_error 回调

fire_complete 类似,但调用的是 on_error 方法。

§Arguments
  • context - 下载失败的上下文信息
  • error - 错误描述字符串
§Returns

返回每个钩子的执行结果描述向量

Source

pub fn hook_count(&self) -> usize

获取当前注册的钩子数量

Source

pub fn clear_hooks(&mut self)

清空所有已注册的钩子

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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