rand_distr::weighted_alias

Trait AliasableWeight

Source
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

Weight bound for 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl AliasableWeight 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 AliasableWeight 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 AliasableWeight for i8

Source§

const MAX: Self = 127i8

Source§

const ZERO: Self = 0i8

Source§

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

Source§

impl AliasableWeight 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 AliasableWeight 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 AliasableWeight 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 AliasableWeight 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 AliasableWeight for u8

Source§

const MAX: Self = 255u8

Source§

const ZERO: Self = 0u8

Source§

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

Source§

impl AliasableWeight 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 AliasableWeight 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 AliasableWeight 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>

Source§

impl AliasableWeight 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 AliasableWeight 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>

Implementors§