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:
- a die with symbols,
- a numeric die without a fixed interval between values
- a numeric die with repeated values
Methods
impl<E: Copy> ValueDie<E>[src]
fn new(vals: Vec<E>, rng: Option<Box<Rng>>) -> Self
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]
type ValueType = E
The type of value the die may have.
fn roll(&mut self) -> &mut Self
Randomize the value of the die, selecting from the values specified at die construction. Read more
fn get_value(&self) -> Self::ValueType
Obtain a copy of the current value of the die. Read more
fn values(&self) -> Vec<Self::ValueType>
Obtain a vector of all possile values the die may take. Read more