pub trait Component:
Send
+ Sync
+ 'static {
type Deps: DepsTuple;
const SCOPE: Scope = Scope::Singleton;
// Required method
fn build(deps: Self::Deps) -> Self;
// Provided methods
fn inner_init(&mut self, store: &Store) -> RIE<()> { ... }
fn init(app: &Arc<App>) -> RIE<()> { ... }
fn async_init(app: &Arc<App>) -> BoxFuture<RIE<()>> { ... }
fn async_run(app: &Arc<App>, token: CancellationToken) -> BoxFuture<RIE<()>> { ... }
fn shutdown(&self) { ... }
fn init_sort() -> i32 { ... }
fn trait_impls() -> &'static [fn() -> TypeId] { ... }
}Expand description
Provided Associated Constants§
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn inner_init(&mut self, store: &Store) -> RIE<()>
fn inner_init(&mut self, store: &Store) -> RIE<()>
build 之后、init 之前调用(同步初始化)
可以访问 Store 注入额外依赖,但主要依赖应通过 Deps 声明。
Sourcefn async_run(app: &Arc<App>, token: CancellationToken) -> BoxFuture<RIE<()>>
fn async_run(app: &Arc<App>, token: CancellationToken) -> BoxFuture<RIE<()>>
异步运行(在独立 task 里调用,直到 CancellationToken 触发)
Sourcefn trait_impls() -> &'static [fn() -> TypeId]
fn trait_impls() -> &'static [fn() -> TypeId]
返回此组件实现的 trait TypeId 列表
由 #[component(as_trait = ...)] 宏自动生成。
默认为空 — 不实现任何 trait。
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".