rand_distr::uniform

Trait SampleRange

Source
pub trait SampleRange<T> {
    // Required methods
    fn sample_single<R>(self, rng: &mut R) -> Result<T, Error>
       where R: RngCore + ?Sized;
    fn is_empty(&self) -> bool;
}
Expand description

Range that supports generating a single sample efficiently.

Any type implementing this trait can be used to specify the sampled range for Rng::random_range.

Required Methods§

Source

fn sample_single<R>(self, rng: &mut R) -> Result<T, Error>
where R: RngCore + ?Sized,

Generate a sample from the given range.

Source

fn is_empty(&self) -> bool

Check whether the range is empty.

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 SampleRange<u8> for RangeTo<u8>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u8, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<u8> for RangeToInclusive<u8>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u8, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<u16> for RangeTo<u16>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u16, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<u16> for RangeToInclusive<u16>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u16, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<u32> for RangeTo<u32>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u32, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<u32> for RangeToInclusive<u32>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u32, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<u64> for RangeTo<u64>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u64, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<u64> for RangeToInclusive<u64>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u64, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<u128> for RangeTo<u128>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u128, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<u128> for RangeToInclusive<u128>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<u128, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<usize> for RangeTo<usize>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<usize, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl SampleRange<usize> for RangeToInclusive<usize>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<usize, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl<T> SampleRange<T> for Range<T>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<T, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Source§

impl<T> SampleRange<T> for RangeInclusive<T>

Source§

fn sample_single<R>(self, rng: &mut R) -> Result<T, Error>
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Implementors§