Skip to main content

ProviderBackend

Trait ProviderBackend 

Source
pub trait ProviderBackend: Send + Sync {
    // Required methods
    fn token(&self) -> Provider;
    fn probe<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        account: &'life1 AccountEnv<'life2>,
        host: &'life3 dyn ProviderHost,
    ) -> Pin<Box<dyn Future<Output = Result<UsageSnapshot, ProbeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn billing(&self) -> BillingModel;
    fn source(&self) -> UsageSourceKind;

    // Provided methods
    fn repair(
        &self,
        _account: &AccountEnv<'_>,
        err: &ProbeError,
    ) -> RepairAction { ... }
    fn budget(
        &self,
        account: &str,
        snapshot: Option<&UsageSnapshot>,
    ) -> AccountBudget { ... }
}
Expand description

One backend per forge.toml provider token. The impls are stateless unit structs; per-account state arrives through AccountEnv, never through self.

Required Methods§

Source

fn token(&self) -> Provider

The token this backend serves; the registry keys on it.

Source

fn probe<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, account: &'life1 AccountEnv<'life2>, host: &'life3 dyn ProviderHost, ) -> Pin<Box<dyn Future<Output = Result<UsageSnapshot, ProbeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

One probe round-trip: credential resolution, URL derivation, headers, status classification, payload-to-snapshot mapping. Strict-vs-lenient mapping lives in the impls, not in a flag.

Source

fn billing(&self) -> BillingModel

Billing shape.

Source

fn source(&self) -> UsageSourceKind

The source kind this backend’s probe stamps on the snapshots it returns; budget refuses a cached snapshot of any other kind.

Provided Methods§

Source

fn repair(&self, _account: &AccountEnv<'_>, err: &ProbeError) -> RepairAction

What this backend allows after a failed probe. The shared default: the auth classes are terminal (an env credential is fixed when the session spawns and there is no local credential repair to fire) and everything else retries. Backends whose provider repairs differently override this.

Source

fn budget( &self, account: &str, snapshot: Option<&UsageSnapshot>, ) -> AccountBudget

The budget shape this backend renders for one account’s cached usage snapshot.

A snapshot whose source is not this backend’s is treated as absent: the redb cache survives a forge.toml provider edit and is re-seeded at every boot, so a stale row is normal, and rendering windows as money (or the reverse) is worse than saying nothing.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§