pub trait RateLimitStreamExt: Stream + Sized {
// Provided methods
fn rate_limit_per_unit(
self,
elements_per_unit: usize,
unit: Duration,
) -> (RateLimitedStream<Self>, RateController) { ... }
fn rate_limit_with_controller(
self,
controller: &RateController,
) -> RateLimitedStream<Self> { ... }
}Expand description
Extension trait to add rate limiting to any stream
Provided Methods§
Sourcefn rate_limit_per_unit(
self,
elements_per_unit: usize,
unit: Duration,
) -> (RateLimitedStream<Self>, RateController)
fn rate_limit_per_unit( self, elements_per_unit: usize, unit: Duration, ) -> (RateLimitedStream<Self>, RateController)
Creates a rate-limited stream that yields elements at the given rate.
The rate can be controlled dynamically during the lifetime of the stream by using
the returned RateController.
If elements_per_unit is 0, the stream will not yield until the limit is changed
using the RateController to a non-zero value.
Sourcefn rate_limit_with_controller(
self,
controller: &RateController,
) -> RateLimitedStream<Self>
fn rate_limit_with_controller( self, controller: &RateController, ) -> RateLimitedStream<Self>
Creates a rate-limited stream that yields elements at the given rate.
The rate can be controlled dynamically during the lifetime of the stream by using
the given RateController.
If the controller has zero rate,
the stream will not yield until the limit is
changed using the RateController to a non-zero value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.