Struct Builder

Source
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 min_wait(&mut self, dur: Duration) -> &mut Self

Sets the minimum wait duration when the speed limit was exceeded.

The default value is same as the refill period.

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> Freeze for Builder<C>
where C: Freeze, <C as Clock>::Instant: Freeze,

§

impl<C> RefUnwindSafe for Builder<C>

§

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 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> 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, 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.