Skip to main content

GrateLimiter

Struct GrateLimiter 

Source
pub struct GrateLimiter { /* private fields */ }
Expand description

The main grate-limiter engine.

Thread-safe and cheaply cloneable. All instances share the same internal state.

§Example

use grate_limiter::{GrateLimiter, EngineConfig};

let engine = GrateLimiter::new(EngineConfig::default());
// Register providers and capabilities, then use engine.select() and engine.observe()

Implementations§

Source§

impl GrateLimiter

Source

pub fn new(config: EngineConfig) -> Self

Create a new engine with the given configuration.

Source

pub fn upsert_provider(&self, config: ProviderConfig)

Register or update a provider and its quotas.

If the provider already exists, its configuration and quota trackers are replaced. Health state is preserved across upserts.

Source

pub fn upsert_capability(&self, config: CapabilityConfig)

Register or update a capability and its provider mappings.

Source

pub fn select(&self, capability: &str) -> Result<Decision>

Select the best provider for a capability.

Returns a Decision with the selected provider, its score, reasoning breakdown, and ranked alternatives.

§Errors
Source

pub fn observe(&self, obs: Observation) -> Result<()>

Report an observation after a provider interaction.

Updates quota counters and health state for the provider.

§Errors
Source

pub fn metrics(&self) -> &Metrics

Access engine metrics.

Source

pub fn provider_health(&self, provider: &str) -> Option<f32>

Get the current health score for a provider.

Source

pub fn provider_in_cooldown(&self, provider: &str) -> Option<bool>

Check if a provider is currently in cooldown.

Source

pub fn provider_quota_remaining( &self, provider: &str, dimension: Dimension, ) -> Option<u64>

Get the remaining quota for a specific dimension on a provider.

Trait Implementations§

Source§

impl Clone for GrateLimiter

Source§

fn clone(&self) -> GrateLimiter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.