pub struct FactoryRegistry { /* private fields */ }Expand description
A registry that maps kind strings (e.g. "provider.openai") to
FactoryInvoker instances.
Invoking an unknown kind returns FactoryError::UnknownKind:
let reg = FactoryRegistry::new();
let ctx = ComponentContext::new(ShutdownToken::new());
let result = reg.invoke("nope", serde_json::json!({}), &ctx);
assert!(result.is_err());
assert!(matches!(result, Err(FactoryError::UnknownKind(_))));Implementations§
Source§impl FactoryRegistry
impl FactoryRegistry
Sourcepub fn register(
self,
kind: &'static str,
invoker: impl FactoryInvoker + 'static,
) -> Self
pub fn register( self, kind: &'static str, invoker: impl FactoryInvoker + 'static, ) -> Self
Registers a factory invoker under the given kind.
Returns self for chaining.
Sourcepub fn kinds(&self) -> impl Iterator<Item = &'static str> + '_
pub fn kinds(&self) -> impl Iterator<Item = &'static str> + '_
Iterates over all registered kind strings.
Sourcepub fn invoke(
&self,
kind: &str,
cfg: Value,
ctx: &ComponentContext,
) -> Result<Box<dyn AnyComponent>, FactoryError>
pub fn invoke( &self, kind: &str, cfg: Value, ctx: &ComponentContext, ) -> Result<Box<dyn AnyComponent>, FactoryError>
Invokes the factory registered for kind with the given JSON config.
§Errors
Returns FactoryError::UnknownKind when no factory is registered,
or the factory’s own error on failure.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for FactoryRegistry
impl !UnwindSafe for FactoryRegistry
impl Freeze for FactoryRegistry
impl Send for FactoryRegistry
impl Sync for FactoryRegistry
impl Unpin for FactoryRegistry
impl UnsafeUnpin for FactoryRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more