Skip to main content

ComponentMeta

Struct ComponentMeta 

Source
pub struct ComponentMeta {
    pub type_id: fn() -> TypeId,
    pub deps: &'static [fn() -> TypeId],
    pub name: &'static str,
    pub scope: Scope,
    pub factory_fn: Option<fn(&mut BuildContext) -> Box<dyn Any + Send + Sync>>,
    pub init_sort_fn: fn() -> i32,
    pub init_fn: Option<fn(&mut BuildContext)>,
    pub async_init_fn: Option<fn(&mut BuildContext) -> BoxFuture<'_, ()>>,
}
Expand description

组件元数据,存储组件的运行时信息和依赖关系。

该结构体由 #[tx_comp] 宏自动生成并注册到 COMPONENT_REGISTRY 中, 用于在运行时进行依赖解析、拓扑排序和组件构建。

§字段说明

  • type_id: 返回组件类型 TypeId 的函数指针,用于唯一标识组件类型
  • deps: 组件的依赖列表,每个元素是返回依赖类型 TypeId 的函数指针
  • name: 组件的类型名称字符串,用于调试和错误提示
  • scope: 组件的作用域(Singleton 或 Prototype),决定实例的生命周期
  • factory_fn: 可选的工厂函数,仅用于调试诊断,运行时不使用

Fields§

§type_id: fn() -> TypeId

返回组件类型 TypeId 的函数指针。

用于在运行时唯一标识组件类型,支持类型安全的依赖查找和向下转型。

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

组件的依赖列表,存储为返回 TypeId 的函数指针数组。

该数组包含所有通过 Arc<T> 注入的依赖项(不包括 #[tx_cst] 标记的字段)。 在拓扑排序阶段用于构建依赖图,检测循环依赖。

§name: &'static str

组件的类型名称字符串。

用于调试输出、错误消息和日志记录,提高可读性。

§scope: Scope

组件的作用域,决定实例的生命周期管理策略。

  • Scope::Singleton: 全局单例,首次注入时构建并缓存
  • Scope::Prototype: 原型模式,每次注入都创建新实例
§factory_fn: Option<fn(&mut BuildContext) -> Box<dyn Any + Send + Sync>>

原始工厂函数,仅用于 debug_registry 诊断;运行时不使用。

该字段为可选,主要用于调试和开发阶段的组件信息查看。 在正式运行时,组件构建通过 ComponentDescriptor::build 方法完成。

§init_sort_fn: fn() -> i32§init_fn: Option<fn(&mut BuildContext)>§async_init_fn: Option<fn(&mut BuildContext) -> BoxFuture<'_, ()>>

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, 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 = 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.