Skip to main content

Weight

Enum Weight 

Source
pub enum Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,
{ Unit(T), Infinity, NaN, }
Expand description

Generic implementation of weight with any units that implement std::ops::Add and std::ops::Sub. This type wraps the unit in a system with an infinity point and a “not a number” point used by the algorithms.

Implements WeightUnit and Zero.

§Example

use core_cbc_casper::util::weight::Weight::{self, *};

assert_eq!(Unit(2), Unit(1) + Unit(1));
assert_eq!(Infinity, Unit(1) + Infinity);
assert_eq!(Weight::<u32>::NaN.to_string(), (Unit(1) + NaN).to_string());

Variants§

§

Unit(T)

§

Infinity

§

NaN

Trait Implementations§

Source§

impl<T> Add for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

type Output = Weight<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl<T> AddAssign for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<T> Clone for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display + Clone,

Source§

fn clone(&self) -> Weight<T>

Returns a duplicate 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<T> Debug for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

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

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

impl<T> Display for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

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

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

impl<T> PartialEq for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Sub for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

type Output = Weight<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl<T> SubAssign for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl<T> WeightUnit for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

const NAN: Self = Weight::NaN

Represent not a number
Source§

const INFINITY: Self = Weight::Infinity

Points to infinity
Source§

impl<T> Zero<Weight<T>> for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display,

Source§

const ZERO: Self

Source§

fn is_zero(val: &Self) -> bool

Returns whether or not the value is equal to zero.
Source§

impl<T> Copy for Weight<T>
where T: Zero<T> + Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Copy + Display + Copy,

Auto Trait Implementations§

§

impl<T> Freeze for Weight<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Weight<T>
where T: RefUnwindSafe,

§

impl<T> Send for Weight<T>
where T: Send,

§

impl<T> Sync for Weight<T>
where T: Sync,

§

impl<T> Unpin for Weight<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Weight<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Weight<T>
where T: UnwindSafe,

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, 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> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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