pub trait Weight: 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 WeightedIndex. Currently no guarantees on the correctness of WeightedIndex 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.

Implementations on Foreign Types§

source§

impl Weight for u32

source§

const MAX: Self = 4_294_967_295u32

source§

const ZERO: Self = 0u32

source§

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

source§

impl Weight for f32

source§

const MAX: Self = 3.40282347E+38f32

source§

const ZERO: Self = 0f32

source§

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

source§

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

source§

impl Weight for i8

source§

const MAX: Self = 127i8

source§

const ZERO: Self = 0i8

source§

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

source§

impl Weight for u8

source§

const MAX: Self = 255u8

source§

const ZERO: Self = 0u8

source§

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

source§

impl Weight for i64

source§

const MAX: Self = 9_223_372_036_854_775_807i64

source§

const ZERO: Self = 0i64

source§

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

source§

impl Weight for f64

source§

const MAX: Self = 1.7976931348623157E+308f64

source§

const ZERO: Self = 0f64

source§

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

source§

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

source§

impl Weight for isize

source§

const MAX: Self = 9_223_372_036_854_775_807isize

source§

const ZERO: Self = 0isize

source§

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

source§

impl Weight for i32

source§

const MAX: Self = 2_147_483_647i32

source§

const ZERO: Self = 0i32

source§

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

source§

impl Weight for usize

source§

const MAX: Self = 18_446_744_073_709_551_615usize

source§

const ZERO: Self = 0usize

source§

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

source§

impl Weight for i128

source§

const MAX: Self = 170_141_183_460_469_231_731_687_303_715_884_105_727i128

source§

const ZERO: Self = 0i128

source§

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

source§

impl Weight for u128

source§

const MAX: Self = 340_282_366_920_938_463_463_374_607_431_768_211_455u128

source§

const ZERO: Self = 0u128

source§

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

source§

impl Weight for u16

source§

const MAX: Self = 65_535u16

source§

const ZERO: Self = 0u16

source§

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

source§

impl Weight for i16

source§

const MAX: Self = 32_767i16

source§

const ZERO: Self = 0i16

source§

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

source§

impl Weight for u64

source§

const MAX: Self = 18_446_744_073_709_551_615u64

source§

const ZERO: Self = 0u64

source§

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

Implementors§