pub struct ModelRegistry { /* private fields */ }Expand description
Provider/model catalog. Cheap to clone (entries shared via Arc).
Implementations§
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn merge(&mut self, other: ModelRegistry)
pub fn merge(&mut self, other: ModelRegistry)
Merges every entry of other into this registry (other wins on key
collision — a remote catalog can therefore override built-in prices).
Sourcepub fn get(&self, provider: &str, model: &str) -> Option<&Arc<ModelInfo>>
pub fn get(&self, provider: &str, model: &str) -> Option<&Arc<ModelInfo>>
Lookup by provider + model id.
Sourcepub fn get_by_key(&self, key: &str) -> Option<&Arc<ModelInfo>>
pub fn get_by_key(&self, key: &str) -> Option<&Arc<ModelInfo>>
Lookup by canonical "<provider>/<id>" key.
Sourcepub fn models(&self) -> impl Iterator<Item = &Arc<ModelInfo>>
pub fn models(&self) -> impl Iterator<Item = &Arc<ModelInfo>>
All registered entries (arbitrary order).
Sourcepub fn models_of<'a>(
&'a self,
provider: &'a str,
) -> impl Iterator<Item = &'a Arc<ModelInfo>> + 'a
pub fn models_of<'a>( &'a self, provider: &'a str, ) -> impl Iterator<Item = &'a Arc<ModelInfo>> + 'a
Entries of one provider.
Sourcepub fn from_json(json: &str) -> Result<Self, CostError>
pub fn from_json(json: &str) -> Result<Self, CostError>
Parses a remote/JSON catalog ({"version":..,"models":[...]} or a bare
[ModelInfo] array).
Sourcepub fn to_json(&self) -> Result<String, CostError>
pub fn to_json(&self) -> Result<String, CostError>
Serializes the registry to the enveloped catalog JSON.
Trait Implementations§
Source§impl Clone for ModelRegistry
impl Clone for ModelRegistry
Source§fn clone(&self) -> ModelRegistry
fn clone(&self) -> ModelRegistry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ModelRegistry
impl Debug for ModelRegistry
Source§impl Default for ModelRegistry
impl Default for ModelRegistry
Source§fn default() -> ModelRegistry
fn default() -> ModelRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ModelRegistry
impl RefUnwindSafe for ModelRegistry
impl Send for ModelRegistry
impl Sync for ModelRegistry
impl Unpin for ModelRegistry
impl UnsafeUnpin for ModelRegistry
impl UnwindSafe for ModelRegistry
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