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
impl GrateLimiter
Sourcepub fn new(config: EngineConfig) -> Self
pub fn new(config: EngineConfig) -> Self
Create a new engine with the given configuration.
Sourcepub fn upsert_provider(&self, config: ProviderConfig)
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.
Sourcepub fn upsert_capability(&self, config: CapabilityConfig)
pub fn upsert_capability(&self, config: CapabilityConfig)
Register or update a capability and its provider mappings.
Sourcepub fn select(&self, capability: &str) -> Result<Decision>
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
Error::UnknownCapabilityif the capability is not registered.Error::NoAvailableProvidersif all providers are in cooldown or below minimum health.
Sourcepub fn observe(&self, obs: Observation) -> Result<()>
pub fn observe(&self, obs: Observation) -> Result<()>
Report an observation after a provider interaction.
Updates quota counters and health state for the provider.
§Errors
Error::UnknownProviderif the provider is not registered.
Sourcepub fn provider_health(&self, provider: &str) -> Option<f32>
pub fn provider_health(&self, provider: &str) -> Option<f32>
Get the current health score for a provider.
Sourcepub fn provider_in_cooldown(&self, provider: &str) -> Option<bool>
pub fn provider_in_cooldown(&self, provider: &str) -> Option<bool>
Check if a provider is currently in cooldown.
Trait Implementations§
Source§impl Clone for GrateLimiter
impl Clone for GrateLimiter
Source§fn clone(&self) -> GrateLimiter
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for GrateLimiter
impl !RefUnwindSafe for GrateLimiter
impl Send for GrateLimiter
impl Sync for GrateLimiter
impl Unpin for GrateLimiter
impl UnsafeUnpin for GrateLimiter
impl !UnwindSafe for GrateLimiter
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