pub struct RunAvg(_, _);
Expand description

Running average that prioritizes memory and cpu efficiency over strict accuracy. For metrics where we can’t afford the memory of tracking samples for every remote we might talk to, this running average is accurate enough and uses only 5 bytes of memory.

Implementations§

source§

impl RunAvg

source

pub fn push<V>(&mut self, v: V)where V: AsPrimitive<f32>,

Push a new data point onto the running average

source

pub fn push_n<V>(&mut self, v: V, count: u8)where V: AsPrimitive<f32>,

Push multiple entries (up to 255) of the same value onto the average

Methods from Deref<Target = f32>§

1.43.0 · source

pub const RADIX: u32 = 2u32

1.43.0 · source

pub const MANTISSA_DIGITS: u32 = 24u32

1.43.0 · source

pub const DIGITS: u32 = 6u32

1.43.0 · source

pub const EPSILON: f32 = 1.1920929E-7f32

1.43.0 · source

pub const MIN: f32 = -3.40282347E+38f32

1.43.0 · source

pub const MIN_POSITIVE: f32 = 1.17549435E-38f32

1.43.0 · source

pub const MAX: f32 = 3.40282347E+38f32

1.43.0 · source

pub const MIN_EXP: i32 = -125i32

1.43.0 · source

pub const MAX_EXP: i32 = 128i32

1.43.0 · source

pub const MIN_10_EXP: i32 = -37i32

1.43.0 · source

pub const MAX_10_EXP: i32 = 38i32

1.43.0 · source

pub const NAN: f32 = NaNf32

1.43.0 · source

pub const INFINITY: f32 = +Inff32

1.43.0 · source

pub const NEG_INFINITY: f32 = -Inff32

1.62.0 · source

pub fn total_cmp(&self, other: &f32) -> Ordering

Return the ordering between self and other.

Unlike the standard partial comparison between floating point numbers, this comparison always produces an ordering in accordance to the totalOrder predicate as defined in the IEEE 754 (2008 revision) floating point standard. The values are ordered in the following sequence:

  • negative quiet NaN
  • negative signaling NaN
  • negative infinity
  • negative numbers
  • negative subnormal numbers
  • negative zero
  • positive zero
  • positive subnormal numbers
  • positive numbers
  • positive infinity
  • positive signaling NaN
  • positive quiet NaN.

The ordering established by this function does not always agree with the PartialOrd and PartialEq implementations of f32. For example, they consider negative and positive zero equal, while total_cmp doesn’t.

The interpretation of the signaling NaN bit follows the definition in the IEEE 754 standard, which may not match the interpretation by some of the older, non-conformant (e.g. MIPS) hardware implementations.

Example
struct GoodBoy {
    name: String,
    weight: f32,
}

let mut bois = vec![
    GoodBoy { name: "Pucci".to_owned(), weight: 0.1 },
    GoodBoy { name: "Woofer".to_owned(), weight: 99.0 },
    GoodBoy { name: "Yapper".to_owned(), weight: 10.0 },
    GoodBoy { name: "Chonk".to_owned(), weight: f32::INFINITY },
    GoodBoy { name: "Abs. Unit".to_owned(), weight: f32::NAN },
    GoodBoy { name: "Floaty".to_owned(), weight: -5.0 },
];

bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));

Trait Implementations§

source§

impl AsRef<f32> for RunAvg

source§

fn as_ref(&self) -> &f32

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<f32> for RunAvg

source§

fn borrow(&self) -> &f32

Immutably borrows from an owned value. Read more
source§

impl Clone for RunAvg

source§

fn clone(&self) -> RunAvg

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for RunAvg

source§

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

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

impl Default for RunAvg

source§

fn default() -> RunAvg

Returns the “default value” for a type. Read more
source§

impl Deref for RunAvg

§

type Target = f32

The resulting type after dereferencing.
source§

fn deref(&self) -> &<RunAvg as Deref>::Target

Dereferences the value.
source§

impl Display for RunAvg

source§

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

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

impl From<f32> for RunAvg

source§

fn from(o: f32) -> RunAvg

Converts to this type from the input type.
source§

impl From<f64> for RunAvg

source§

fn from(o: f64) -> RunAvg

Converts to this type from the input type.
source§

impl From<i16> for RunAvg

source§

fn from(o: i16) -> RunAvg

Converts to this type from the input type.
source§

impl From<i32> for RunAvg

source§

fn from(o: i32) -> RunAvg

Converts to this type from the input type.
source§

impl From<i64> for RunAvg

source§

fn from(o: i64) -> RunAvg

Converts to this type from the input type.
source§

impl From<i8> for RunAvg

source§

fn from(o: i8) -> RunAvg

Converts to this type from the input type.
source§

impl From<u16> for RunAvg

source§

fn from(o: u16) -> RunAvg

Converts to this type from the input type.
source§

impl From<u32> for RunAvg

source§

fn from(o: u32) -> RunAvg

Converts to this type from the input type.
source§

impl From<u64> for RunAvg

source§

fn from(o: u64) -> RunAvg

Converts to this type from the input type.
source§

impl From<u8> for RunAvg

source§

fn from(o: u8) -> RunAvg

Converts to this type from the input type.
source§

impl Copy for RunAvg

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for Twhere T: Any,

§

fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>

§

fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T, Global>) -> Arc<dyn Any + Send + Sync, Global>

§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
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> 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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

impl<T> Upcastable for Twhere T: Any + Send + Sync + 'static,

§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
§

fn upcast_any_box(self: Box<T, Global>) -> Box<dyn Any, Global>

upcast boxed dyn
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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

impl<T> State for Twhere T: Debug + Clone + Send + Sync,