pub trait AliasableWeight:
    Sized
    + Copy
    + SampleUniform
    + PartialOrd
    + Add<Output = Self>
    + AddAssign
    + Sub<Output = Self>
    + SubAssign
    + Mul<Output = Self>
    + MulAssign
    + Div<Output = Self>
    + DivAssign
    + Sum {
    const MAX: Self;
    const ZERO: Self;

    // Required method
    fn try_from_u32_lossy(n: u32) -> Option<Self>;

    // Provided method
    fn sum(values: &[Self]) -> Self { ... }
}
Expand description

Trait that must be implemented for weights, that are used with WeightedAliasIndex. Currently no guarantees on the correctness of WeightedAliasIndex are given for custom implementations of this trait.

Required Associated Constants§

source

const MAX: Self

Maximum number representable by Self.

source

const ZERO: Self

Element of Self equivalent to 0.

Required Methods§

source

fn try_from_u32_lossy(n: u32) -> Option<Self>

Produce an instance of Self from a u32 value, or return None if out of range. Loss of precision (where Self is a floating point type) is acceptable.

Provided Methods§

source

fn sum(values: &[Self]) -> Self

Sums all values in slice values.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl AliasableWeight for f32

source§

const MAX: f32 = 3.40282347E+38f32

source§

const ZERO: f32 = 0f32

source§

fn try_from_u32_lossy(n: u32) -> Option<f32>

source§

fn sum(values: &[f32]) -> f32

source§

impl AliasableWeight for f64

source§

const MAX: f64 = 1.7976931348623157E+308f64

source§

const ZERO: f64 = 0f64

source§

fn try_from_u32_lossy(n: u32) -> Option<f64>

source§

fn sum(values: &[f64]) -> f64

source§

impl AliasableWeight for i8

source§

const MAX: i8 = 127i8

source§

const ZERO: i8 = 0i8

source§

fn try_from_u32_lossy(n: u32) -> Option<i8>

source§

impl AliasableWeight for i16

source§

const MAX: i16 = 32_767i16

source§

const ZERO: i16 = 0i16

source§

fn try_from_u32_lossy(n: u32) -> Option<i16>

source§

impl AliasableWeight for i32

source§

const MAX: i32 = 2_147_483_647i32

source§

const ZERO: i32 = 0i32

source§

fn try_from_u32_lossy(n: u32) -> Option<i32>

source§

impl AliasableWeight for i64

source§

const MAX: i64 = 9_223_372_036_854_775_807i64

source§

const ZERO: i64 = 0i64

source§

fn try_from_u32_lossy(n: u32) -> Option<i64>

source§

impl AliasableWeight for i128

source§

const MAX: i128 = 170_141_183_460_469_231_731_687_303_715_884_105_727i128

source§

const ZERO: i128 = 0i128

source§

fn try_from_u32_lossy(n: u32) -> Option<i128>

source§

impl AliasableWeight for isize

source§

const MAX: isize = 2_147_483_647isize

source§

const ZERO: isize = 0isize

source§

fn try_from_u32_lossy(n: u32) -> Option<isize>

source§

impl AliasableWeight for u8

source§

const MAX: u8 = 255u8

source§

const ZERO: u8 = 0u8

source§

fn try_from_u32_lossy(n: u32) -> Option<u8>

source§

impl AliasableWeight for u16

source§

const MAX: u16 = 65_535u16

source§

const ZERO: u16 = 0u16

source§

fn try_from_u32_lossy(n: u32) -> Option<u16>

source§

impl AliasableWeight for u32

source§

const MAX: u32 = 4_294_967_295u32

source§

const ZERO: u32 = 0u32

source§

fn try_from_u32_lossy(n: u32) -> Option<u32>

source§

impl AliasableWeight for u64

source§

const MAX: u64 = 18_446_744_073_709_551_615u64

source§

const ZERO: u64 = 0u64

source§

fn try_from_u32_lossy(n: u32) -> Option<u64>

source§

impl AliasableWeight for u128

source§

const MAX: u128 = 340_282_366_920_938_463_463_374_607_431_768_211_455u128

source§

const ZERO: u128 = 0u128

source§

fn try_from_u32_lossy(n: u32) -> Option<u128>

source§

impl AliasableWeight for usize

source§

const MAX: usize = 4_294_967_295usize

source§

const ZERO: usize = 0usize

source§

fn try_from_u32_lossy(n: u32) -> Option<usize>

Implementors§