Skip to main content

bb_ir/
registry.rs

1//! Concrete-component inventory registry. Derive macros submit
2//! per-type entries; the linker preserves them if the type is
3//! referenced. Custom-op registry lives in `bb_runtime::registry`.
4
5use crate::component::{ComponentPackage, ConstructFn, DependencyDecl, RestoreFn, SerializeFn};
6
7/// Inventory entry for a concrete component, keyed by `TYPE_NAME`.
8pub struct ConcreteComponentRegistration {
9    /// `ConcreteComponent::TYPE_NAME`.
10    pub type_name: &'static str,
11    /// Package origin.
12    pub package: ComponentPackage,
13    /// Monomorphized `T::serialize`.
14    pub serialize_fn: SerializeFn,
15    /// Monomorphized `T::restore`.
16    pub restore_fn: RestoreFn,
17    /// Downcasts `&dyn Any` → `&T::Config` then calls `T::new`.
18    pub construct_fn: ConstructFn,
19    /// Mirror of `ConcreteComponent::DEPENDENCIES`.
20    pub dependencies: &'static [DependencyDecl],
21}
22
23inventory::collect!(ConcreteComponentRegistration);
24
25/// Look up a concrete by `TYPE_NAME`. `None` when unregistered in
26/// this binary.
27pub fn find_concrete_component(type_name: &str) -> Option<&'static ConcreteComponentRegistration> {
28    inventory::iter::<ConcreteComponentRegistration>
29        .into_iter()
30        .find(|r| r.type_name == type_name)
31}
32
33/// Iterate every concrete-component registration this binary links.
34pub fn concrete_components() -> impl Iterator<Item = &'static ConcreteComponentRegistration> {
35    inventory::iter::<ConcreteComponentRegistration>.into_iter()
36}
37
38/// Re-export for derive-macro emit sites.
39pub use inventory;