Skip to main content

ProviderIdentityExt

Trait ProviderIdentityExt 

Source
pub trait ProviderIdentityExt: ProviderIdentity {
    // Provided method
    fn downcast_ref<T: Any + Send + Sync>(&self) -> Option<&T> { ... }
}
Expand description

Provided Methods§

Source

fn downcast_ref<T: Any + Send + Sync>(&self) -> Option<&T>

Borrow the T this provider, or a provider it wraps, exposes.

Like anyhow::Error::downcast_ref, this looks through layers: it reaches a concrete provider (and its provider-specific methods) through wrappers and DynChatProvider:

use allama::mock::MockProvider;
use allama::wrappers::{RetryPolicy, RetryingProvider};
use allama::{DynChatProvider, ProviderIdentityExt};

let retrying = RetryingProvider::new(MockProvider::empty(), RetryPolicy::default());
let provider = DynChatProvider::new(retrying);
assert!(provider.downcast_ref::<MockProvider>().is_some());
  • Calls through the result skip the wrappers. The reference points at the inner provider, so its methods run without the retries, timeouts, tracing, or recording around it.
  • The first match wins. A FallbackProvider answers from its primary first; when both sides have the same type, reach each one with primary and fallback.
  • Discovery is for code handed an already-wrapped provider. An application that builds the stack can keep a clone (or an Arc) of the concrete provider before wrapping it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§