pub trait ComponentDescriptor: CompInit {
const DEP_IDS: &'static [fn() -> TypeId];
const SCOPE: Scope;
// Required method
fn build(ctx: &mut BuildContext) -> Self;
}Expand description
组件描述符 trait,用于在编译期定义组件的元数据和构建逻辑。
该 trait 由 #[tx_comp] 宏自动生成实现,是依赖注入框架的核心接口。
每个被标记为组件的结构体都必须实现此 trait,以提供以下信息:
- 组件的依赖关系(通过
DEP_IDS) - 组件的作用域(通过
SCOPE) - 组件的构建方式(通过
build方法)
§Trait 约束
Any: 支持运行时类型识别,用于类型擦除和向下转型Sized: 编译期已知大小,确保可以存储在栈上Send + Sync: 支持跨线程安全传递和共享,因为组件会被存入Arc'static: 生命周期为静态,确保组件可以长期存活
Required Associated Constants§
Required Methods§
Sourcefn build(ctx: &mut BuildContext) -> Self
fn build(ctx: &mut BuildContext) -> Self
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.