pub struct BackendFactory { /* private fields */ }Expand description
Dispatch table from backend family to its constructor function.
A composable primitive: family -> constructor, with no held configuration and no caching.
Each create call builds a fresh shared backend; downstream that wants
sharing caches the returned Arc or clones the crate::ChatClient built from it.
Constructors and family names come from the LlmBackend trait itself
(LlmBackend::new / LlmBackend::family) — every backend type carries them. The common
entry point is new, which pre-seeds every compiled-in built-in backend; use
empty for full control over registration.
Implementations§
Source§impl BackendFactory
impl BackendFactory
Sourcepub fn new() -> Self
pub fn new() -> Self
A factory pre-seeded with every compiled-in built-in backend.
The common path: under default features both the DeepSeek and OpenAI-compatible backends
are registered automatically. With no backend features enabled this yields an empty factory
(equivalent to empty).
Sourcepub fn empty() -> Self
pub fn empty() -> Self
An empty factory; the caller registers backends explicitly via register.
Sourcepub fn register<C: LlmBackend>(&mut self) -> &mut Self
pub fn register<C: LlmBackend>(&mut self) -> &mut Self
Register (or replace) a backend, keyed on its LlmBackend::family.
Captures LlmBackend::new as the constructor. Takes only a type parameter, so the call
requires turbofish: factory.register::<DeepSeekBackend>(). Registering a family that is
already registered replaces the previous constructor.
Sourcepub fn create(
&self,
family: &str,
http: ClientBuilder,
api_key: &str,
base_url: Option<&str>,
) -> Result<Arc<dyn LlmBackend>, BackendConstructError>
pub fn create( &self, family: &str, http: ClientBuilder, api_key: &str, base_url: Option<&str>, ) -> Result<Arc<dyn LlmBackend>, BackendConstructError>
Build a shared backend for family from raw inputs.
Returns BackendConstructError::unknown_family
when no constructor is registered for family.