cap_rand::distributions::uniform

Trait SampleRange

Source
pub trait SampleRange<T> {
    // Required methods
    fn sample_single<R>(self, rng: &mut R) -> T
       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::gen_range.

Required Methods§

Source

fn sample_single<R>(self, rng: &mut R) -> T
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<T> SampleRange<T> for Range<T>

Source§

fn sample_single<R>(self, rng: &mut R) -> T
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) -> T
where R: RngCore + ?Sized,

Source§

fn is_empty(&self) -> bool

Implementors§