pub struct RateLimit { /* private fields */ }Expand description
How often a peer may send unprompted messages: count per period, with bursts of up to
burst at once.
Every constructor refuses a zero, so a RateLimit that exists is one that admits
something — a count of zero is a configuration mistake, not a request to refuse every
station.
// 120 a minute, sustained; up to 20 back to back (a boot's StatusNotifications).
let rate = RateLimit::per_minute(120)?.with_burst(20)?;
assert_eq!(rate.burst(), 20);
assert!(RateLimit::per_minute(0).is_err());Implementations§
Source§impl RateLimit
impl RateLimit
Sourcepub const fn new(count: u32, period: Duration) -> Result<Self, InvalidRateLimit>
pub const fn new(count: u32, period: Duration) -> Result<Self, InvalidRateLimit>
count messages per period, in bursts of up to count.
§Errors
InvalidRateLimit when count is zero or period is shorter than a microsecond.
Sourcepub const fn per_second(count: u32) -> Result<Self, InvalidRateLimit>
pub const fn per_second(count: u32) -> Result<Self, InvalidRateLimit>
Sourcepub const fn per_minute(count: u32) -> Result<Self, InvalidRateLimit>
pub const fn per_minute(count: u32) -> Result<Self, InvalidRateLimit>
Sourcepub const fn with_burst(self, burst: u32) -> Result<Self, InvalidRateLimit>
pub const fn with_burst(self, burst: u32) -> Result<Self, InvalidRateLimit>
How many messages may arrive back to back before the sustained rate applies.
Defaults to count. Set it to at least what a station sends unprompted right after
booting — one StatusNotification per connector, and whatever else its firmware
flushes — or a conforming station is refused at every boot.
§Errors
InvalidRateLimit::ZeroBurst when burst is zero.
Trait Implementations§
impl Copy for RateLimit
impl Eq for RateLimit
impl StructuralPartialEq for RateLimit
Auto Trait Implementations§
impl Forget for RateLimit
impl Freeze for RateLimit
impl Move for RateLimit
impl RefUnwindSafe for RateLimit
impl Send for RateLimit
impl Sync for RateLimit
impl Unpin for RateLimit
impl UnsafeUnpin for RateLimit
impl UnwindSafe for RateLimit
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