Skip to main content

Rate

Struct Rate 

Source
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§

Source§

impl Rate

Source

pub const fn new(units: u64, per: Duration) -> Self

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));
Source

pub const fn try_new(units: u64, per: Duration) -> Option<Self>

Create a new Rate of units per per period, or None for the invalid inputs that make Rate::new panic.

Source

pub const fn per_sec(units: u64) -> Self

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));
Source

pub const fn units(&self) -> u64

The number of units per Rate::per period.

Source

pub const fn per(&self) -> Duration

The period over which Rate::units units are allowed.

Trait Implementations§

Source§

impl Clone for Rate

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Rate

Source§

impl Debug for Rate

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Rate

Source§

impl Hash for Rate

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Rate

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more