pub struct Builder<C: Clock> { /* private fields */ }
Expand description

Builder for Limiter.

Examples

use async_speed_limit::Limiter;
use std::time::Duration;

let limiter = <Limiter>::builder(1_048_576.0)
    .refill(Duration::from_millis(100))
    .build();

Implementations§

source§

impl<C: Clock> Builder<C>

source

pub fn new(speed_limit: f64) -> Self

Creates a new limiter builder.

Use infinity to make the speed unlimited.

source

pub fn speed_limit(&mut self, speed_limit: f64) -> &mut Self

Sets the speed limit of the limiter.

Use infinity to make the speed unlimited.

Panics

The speed limit must be positive. Panics if the speed limit is negative, zero, or NaN.

source

pub fn refill(&mut self, dur: Duration) -> &mut Self

Sets the refill period of the limiter.

The default value is 0.1 s, which should be good for most use cases. The refill period is ignored if the speed is infinity.

Panics

The duration must not be zero, otherwise this method panics.

source

pub fn clock(&mut self, clock: C) -> &mut Self

Sets the clock instance used by the limiter.

source

pub fn build(&mut self) -> Limiter<C>

Builds the limiter.

Trait Implementations§

source§

impl<C: Debug + Clock> Debug for Builder<C>where C::Instant: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> RefUnwindSafe for Builder<C>where C: RefUnwindSafe, <C as Clock>::Instant: RefUnwindSafe,

§

impl<C> Send for Builder<C>where C: Send, <C as Clock>::Instant: Send,

§

impl<C> Sync for Builder<C>where C: Sync, <C as Clock>::Instant: Sync,

§

impl<C> Unpin for Builder<C>where C: Unpin, <C as Clock>::Instant: Unpin,

§

impl<C> UnwindSafe for Builder<C>where C: UnwindSafe, <C as Clock>::Instant: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.