[][src]Struct dicetest::Fate

pub struct Fate<'a> { /* fields omitted */ }

Contains parameters for controlling the value generation with DieOnce and Die.

The first parameter is a Prng. It is the only source of randomness that a implementor of DieOnce or Die is allowed to use. Using the Prng will mutate its state, but for the cause of preventing misuse there is no direct write access to it.

The second parameter is a Limit. It's the upper limit for the size of dynamic data structures generated by the implementor of DieOnce or Die. The implementor has only read access to the Limit.

Implementations

impl<'a> Fate<'a>[src]

pub fn new(prng: &'a mut Prng, limit: Limit) -> Self[src]

Creates a new instance that uses the given parameters for value generation.

pub fn next_number(&mut self) -> u64[src]

Returns the next pseudorandom number generated with the underlying Prng.

pub fn fork_prng(&mut self) -> Prng[src]

Returns a Prng split off from the underlying Prng.

pub fn limit(&self) -> Limit[src]

Returns the underlying Limit.

pub fn copy(&mut self) -> Fate<'_>[src]

Creates a borrowed copy.

Fate cannot implement the Copy trait because it contains a mutable reference. When it's necessary to move Fate multiple times this functions provides a convenient workaround.

Example

use dicetest::{Limit, Fate, Prng};

let mut prng = Prng::from_seed(42.into());
let limit = Limit::default();
let mut fate = Fate::new(&mut prng, limit);

pub fn take_fate(_fate: Fate) {}

take_fate(fate.copy());
take_fate(fate);

pub fn with_limit(&mut self, limit: Limit) -> Fate<'_>[src]

Creates a copy with the given limit.

pub fn roll<T, D: DieOnce<T>>(&mut self, die: D) -> T[src]

Generates a value with the given DiceOnce using self as parameter.

This function is more convenient than calling DiceOnce::roll_once directly because it borrows the Fate instead of moving it.

use dicetest::prelude::*;
use dicetest::{Limit, Prng};

let mut prng = Prng::from_seed(42.into());
let limit = Limit::default();
let mut fate = Fate::new(&mut prng, limit);

let die = dice::bool();

let val1 = fate.roll(&die); // Borrows `fate`
let val2 = die.roll(fate); // Moves `fate`

Auto Trait Implementations

impl<'a> RefUnwindSafe for Fate<'a>

impl<'a> Send for Fate<'a>

impl<'a> Sync for Fate<'a>

impl<'a> Unpin for Fate<'a>

impl<'a> !UnwindSafe for Fate<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.