pub struct Bucket { /* private fields */ }Available on crate feature
server only.Expand description
A token bucket used for rate-limiting.
The bucket holds up to max tokens, refilled at a fixed rate of
bytes_per_second over refill_period intervals. Bucket::consume drains
tokens and reports when the next attempt is allowed.
Exposed so that embedders mounting the relay protocol on a custom HTTP
server (where the stream is already framed and the internal
RateLimited wrapper cannot be used) can apply the same rate-limit
semantics at the frame layer.
Implementations§
Source§impl Bucket
impl Bucket
Sourcepub fn new(
max: i64,
bytes_per_second: i64,
refill_period: Duration,
) -> Result<Self, InvalidBucketConfig>
pub fn new( max: i64, bytes_per_second: i64, refill_period: Duration, ) -> Result<Self, InvalidBucketConfig>
Creates a new bucket starting full at max tokens, refilled at
bytes_per_second over refill_period intervals.
§Errors
Returns InvalidBucketConfig when max, bytes_per_second, or
refill_period are non-positive, or when the configuration would refill
less than one token per period.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bucket
impl RefUnwindSafe for Bucket
impl Send for Bucket
impl Sync for Bucket
impl Unpin for Bucket
impl UnwindSafe for Bucket
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more