Skip to main content

BackendFactory

Struct BackendFactory 

Source
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

Source

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).

Source

pub fn empty() -> Self

An empty factory; the caller registers backends explicitly via register.

Source

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.

Source

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.

Source

pub fn families(&self) -> impl Iterator<Item = &str>

The family names of every registered constructor.

Trait Implementations§

Source§

impl Default for BackendFactory

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more