Struct Rate
pub struct Rate { /* private fields */ }Expand description
A rate: units per per period.
Units are dimensionless: use it for requests, connections, messages
or bytes alike. For byte rates Rate::per_sec is bytes/sec;
compose with crate::octets helpers for larger units.
Implementations§
§impl Rate
impl Rate
pub const fn new(units: u64, per: Duration) -> Rate
Available on crate features grpc and http and std only.
pub const fn new(units: u64, per: Duration) -> Rate
grpc and http and std only.Create a new Rate of units per per period.
§Panics
Panics if units is zero, per is zero, or per exceeds
u64::MAX nanoseconds (~584 years). In const contexts this is
a compile-time error. Use Rate::try_new for fallible
construction from dynamic input.
§Examples
use std::time::Duration;
use rama_utils::rate::Rate;
const RATE: Rate = Rate::new(100, Duration::from_millis(250));
assert_eq!(RATE.units(), 100);
assert_eq!(RATE.per(), Duration::from_millis(250));pub const fn try_new(units: u64, per: Duration) -> Option<Rate>
Available on crate features grpc and http and std only.
pub const fn try_new(units: u64, per: Duration) -> Option<Rate>
grpc and http and std only.pub const fn per_sec(units: u64) -> Rate
Available on crate features grpc and http and std only.
pub const fn per_sec(units: u64) -> Rate
grpc and http and std only.Create a new Rate of units per second.
For byte rates this is bytes per second; combine with
crate::octets::kib_u64, crate::octets::mib_u64 and
crate::octets::gib_u64 for KiB/MiB/GiB rates, and with
crate::octets::from_bits_u64 for link rates expressed in bits.
§Panics
Panics if units is zero (compile-time error in const contexts).
§Examples
use rama_utils::{octets, rate::Rate};
// 100 requests per second
const REQ_RATE: Rate = Rate::per_sec(100);
// 10 MiB per second
const BYTE_RATE: Rate = Rate::per_sec(octets::mib_u64(10));
// a 100 Mbit/s link rate
const LINK_RATE: Rate = Rate::per_sec(octets::from_bits_u64(100_000_000));pub const fn units(&self) -> u64
Available on crate features grpc and http and std only.
pub const fn units(&self) -> u64
grpc and http and std only.The number of units per Rate::per period.
pub const fn per(&self) -> Duration
Available on crate features grpc and http and std only.
pub const fn per(&self) -> Duration
grpc and http and std only.The period over which Rate::units units are allowed.
Trait Implementations§
impl Copy for Rate
impl Eq for Rate
impl StructuralPartialEq for Rate
Auto Trait Implementations§
impl Freeze for Rate
impl RefUnwindSafe for Rate
impl Send for Rate
impl Sync for Rate
impl Unpin for Rate
impl UnsafeUnpin for Rate
impl UnwindSafe for Rate
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§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> ⓘ
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> ⓘ
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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more