Die

Trait Die 

Source
pub trait Die<T>: DieOnce<T> {
    // Required method
    fn roll(&self, fate: Fate<'_>) -> T;

    // Provided methods
    fn map<U, F>(self, f: F) -> MapDie<T, U, Self, F>
       where Self: Sized,
             F: Fn(T) -> U { ... }
    fn flatten<U>(self) -> FlattenDie<U, T, Self>
       where Self: Sized,
             T: DieOnce<U> { ... }
    fn flat_map<U, UD, F>(self, f: F) -> FlatMapDie<T, U, Self, UD, F>
       where Self: Sized,
             UD: DieOnce<U>,
             F: Fn(T) -> UD { ... }
    fn boxed<'a>(self) -> BoxedDie<'a, T>
       where Self: Sized + 'a { ... }
    fn rc<'a>(self) -> RcDie<'a, T>
       where Self: Sized + 'a { ... }
    fn arc(self) -> ArcDie<T>
       where Self: Sized + 'static { ... }
}
Expand description

Trait for generating pseudorandom values of type T.

The Die trait represents a subset of DieOnce. It mirrors all methods of DieOnce without the suffix _once. These methods must behave in the same way. For example an implementation of Die must produce the same value with its methods roll and roll_once if they are called with the same Fate.

Required Methods§

Source

fn roll(&self, fate: Fate<'_>) -> T

Generates a pseudorandom value.

The Fate is the only source of the randomness. Besides that, the generation is deterministic.

Provided Methods§

Source

fn map<U, F>(self, f: F) -> MapDie<T, U, Self, F>
where Self: Sized, F: Fn(T) -> U,

Creates a new Die by mapping the generated values of self.

The function f will be applied to the generated values of self. The results of the function are the generated values of the new Die.

Source

fn flatten<U>(self) -> FlattenDie<U, T, Self>
where Self: Sized, T: DieOnce<U>,

Creates a new Die whose values are generated by the generated Dies of self.

Source

fn flat_map<U, UD, F>(self, f: F) -> FlatMapDie<T, U, Self, UD, F>
where Self: Sized, UD: DieOnce<U>, F: Fn(T) -> UD,

Creates a new Die similar to map, except that the mapping produces DieOnces.

The function f will be applied to the generated values of self. The results of the function are DieOnces that generates the values for the new Die.

It is semantically equivalent to self.map(f).flatten().

Source

fn boxed<'a>(self) -> BoxedDie<'a, T>
where Self: Sized + 'a,

Puts self behind a Box pointer.

Source

fn rc<'a>(self) -> RcDie<'a, T>
where Self: Sized + 'a,

Puts self behind an Rc pointer.

Source

fn arc(self) -> ArcDie<T>
where Self: Sized + 'static,

Puts self behind an Arc pointer.

Implementations on Foreign Types§

Source§

impl<T, TD: Die<T>> Die<T> for &TD

Source§

fn roll(&self, fate: Fate<'_>) -> T

Implementors§

Source§

impl<'a, T> Die<T> for BoxedDie<'a, T>

Source§

impl<'a, T> Die<T> for RcDie<'a, T>

Source§

impl<T> Die<T> for ArcDie<T>

Source§

impl<T, TD, TDD> Die<T> for FlattenDie<T, TD, TDD>
where TD: DieOnce<T>, TDD: Die<TD>,

Source§

impl<T, U, D, F> Die<U> for MapDie<T, U, D, F>
where D: Die<T>, F: Fn(T) -> U,

Source§

impl<T, U, TD, UD, F> Die<U> for FlatMapDie<T, U, TD, UD, F>
where TD: Die<T>, UD: DieOnce<U>, F: Fn(T) -> UD,