Struct ezra::dice::value_die::ValueDie [] [src]

pub struct ValueDie<E: Copy> { /* fields omitted */ }

A die that has values of a fixed type, but no other relationship between the values must exist.

For example:

Methods

impl<E: Copy> ValueDie<E>
[src]

Pseudo-constructor for ValueDie.

Parameters
  • vals : non-empty vector containing all possible die values; may contain duplicates
  • rng : optional RNG; if None, defaults to a ThreadRng
Return value

A ValueDie constructed to the given specifications

Examples

extern crate rand;
use ezra::dice::{Die,ValueDie};
use rand::OsRng;

// Values a die may have
#[derive(Copy,Clone,Debug)]
enum DiceValues {
    Value1,
    Value2,
    Value3,
}

let values = vec![DiceValues::Value1, DiceValues::Value2, DiceValues::Value3];
let rng = OsRng::new().unwrap();
let mut die = ValueDie::new(values, Some(Box::new(rng)));

println!("The value {:?} was rolled.", die.roll().get_value()); 

The die may be constructed without an RNG, defaulting to its own thread-local RNG.

// Values a die may have
#[derive(Copy,Clone)]
enum DiceValues {
    Value1,
    Value2,
    Value3,
}

let values = vec![DiceValues::Value1, DiceValues::Value2, DiceValues::Value3];
let mut die = ValueDie::new(values, None);

Trait Implementations

impl<E: Copy> Die for ValueDie<E>
[src]

The type of value the die may have.

Randomize the value of the die, selecting from the values specified at die construction. Read more

Obtain a copy of the current value of the die. Read more

Obtain a vector of all possile values the die may take. Read more

impl<E: Display + Copy> Display for ValueDie<E>
[src]

Formats the value using the given formatter.