Skip to main content

ComponentMeta

Struct ComponentMeta 

Source
pub struct ComponentMeta {
    pub type_id: fn() -> TypeId,
    pub name: &'static str,
    pub dep_type_ids: &'static [fn() -> TypeId],
    pub factory: fn(&Store) -> Box<dyn Any + Send + Sync>,
    pub scope: Scope,
    pub impl_traits: &'static [fn() -> TypeId],
    pub trait_impls: &'static [TraitImplEntry],
    pub init_sort_fn: fn() -> i32,
    pub init_fn: fn(&Arc<App>) -> RIE<()>,
    pub async_init_fn: fn(&Arc<App>) -> BoxFuture<RIE<()>>,
    pub async_run_fn: fn(&Arc<App>, CancellationToken) -> BoxFuture<RIE<()>>,
    pub shutdown_fn: fn(&Store),
}
Expand description

组件注册元数据(linkme 收集用)

核心字段 + 生命周期函数指针。 函数指针由宏生成,内部调用 <T as Component>::xxx(), 解决 ComponentMeta 类型擦除后无法调用 trait 方法的问题。

Fields§

§type_id: fn() -> TypeId

返回组件类型 TypeId

§name: &'static str

组件类型名(调试用)

§dep_type_ids: &'static [fn() -> TypeId]

依赖类型 ID 列表(用于拓扑排序)

§factory: fn(&Store) -> Box<dyn Any + Send + Sync>

工厂函数:从 Store 构建组件,返回类型擦除的 Box

§scope: Scope

作用域

§impl_traits: &'static [fn() -> TypeId]

该组件实现的 trait TypeId 列表

§trait_impls: &'static [TraitImplEntry]

trait 实现条目列表(用于填充 TRAIT_IMPL_MAP)

§init_sort_fn: fn() -> i32

初始化排序值(值越小越先执行)

§init_fn: fn(&Arc<App>) -> RIE<()>

同步初始化(App 阶段)

§async_init_fn: fn(&Arc<App>) -> BoxFuture<RIE<()>>

异步初始化(App 阶段)

§async_run_fn: fn(&Arc<App>, CancellationToken) -> BoxFuture<RIE<()>>

异步运行(后台 task)

§shutdown_fn: fn(&Store)

优雅关闭

Implementations§

Source§

impl ComponentMeta

Source

pub fn build(&self, store: &Store) -> Box<dyn Any + Send + Sync>

调用工厂函数构建组件实例

Source

pub fn type_id(&self) -> TypeId

获取组件类型 ID

Source

pub fn dep_ids(&self) -> Vec<TypeId>

获取依赖类型 ID 列表

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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