pub struct Check<'a, P: RateLimitPolicy + ?Sized = FixedWindowPolicy> { /* private fields */ }Expand description
One proposed quota charge against a policy and opaque subject.
A newly constructed check has cost 1. Custom costs are validated against the referenced policy so a backend never receives a zero-cost or intrinsically impossible check.
Implementations§
Source§impl<'a, P: RateLimitPolicy + ?Sized> Check<'a, P>
impl<'a, P: RateLimitPolicy + ?Sized> Check<'a, P>
Sourcepub const fn new(policy: &'a P, subject: SubjectKey) -> Self
pub const fn new(policy: &'a P, subject: SubjectKey) -> Self
Constructs a check with the default cost of 1.
Sourcepub fn with_cost(
policy: &'a P,
subject: SubjectKey,
cost: u64,
) -> Result<Self, CheckError>
pub fn with_cost( policy: &'a P, subject: SubjectKey, cost: u64, ) -> Result<Self, CheckError>
Validates and constructs a check with a custom cost.
§Errors
Returns an error when cost is zero or exceeds the policy capacity.
Sourcepub fn try_with_cost(self, cost: u64) -> Result<Self, CheckError>
pub fn try_with_cost(self, cost: u64) -> Result<Self, CheckError>
Returns this check with a validated custom cost.
§Errors
Returns an error when cost is zero or exceeds the policy capacity.
Sourcepub const fn subject(&self) -> SubjectKey
pub const fn subject(&self) -> SubjectKey
Returns the opaque subject key evaluated by this check.
Sourcepub fn counter_key(&self) -> CounterKey
pub fn counter_key(&self) -> CounterKey
Returns the complete logical identity of the stored counter.
Trait Implementations§
impl<P: RateLimitPolicy + ?Sized> Copy for Check<'_, P>
impl<'a, P: Eq + RateLimitPolicy + ?Sized> Eq for Check<'a, P>
impl<'a, P: PartialEq + RateLimitPolicy + ?Sized> StructuralPartialEq for Check<'a, P>
Auto Trait Implementations§
impl<'a, P> Freeze for Check<'a, P>where
P: ?Sized,
impl<'a, P> RefUnwindSafe for Check<'a, P>where
P: RefUnwindSafe + ?Sized,
impl<'a, P> Send for Check<'a, P>where
P: ?Sized,
impl<'a, P> Sync for Check<'a, P>where
P: ?Sized,
impl<'a, P> Unpin for Check<'a, P>where
P: ?Sized,
impl<'a, P> UnsafeUnpin for Check<'a, P>where
P: ?Sized,
impl<'a, P> UnwindSafe for Check<'a, P>where
P: RefUnwindSafe + ?Sized,
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