# [−] [src] Trait rand::distributions::weighted::alias_method::Weight

    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;

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

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

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.

## Associated Constants

### `const MAX: Self`

Maximum number representable by `Self`.

### `const ZERO: Self`

Element of `Self` equivalent to 0.

Loading content...

## Required methods

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

Loading content...

## Provided methods

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

Sums all values in slice `values`.

Loading content...

## Implementations on Foreign Types

### `impl Weight for f64` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for f32` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for usize` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for u128` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for u64` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for u32` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for u16` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for u8` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for isize` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for i128` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for i64` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for i32` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for i16` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

### `impl Weight for i8` [src]

#### `const MAX: Self` [src]

#### `const ZERO: Self` [src]

#### `fn try_from_u32_lossy(n: u32) -> Option<Self>` [src]

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

Loading content...

## Implementors

Loading content...

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)