[][src]Struct one_d_six::Dice

pub struct Dice<T: Rollable = u32> { /* fields omitted */ }

A Handful of dice.

Examples

use one_d_six::Dice;

let mut dice: Dice = "3d6".parse().unwrap();

assert!(dice.roll_all().total() >= 3);
assert!(dice.total() <= 18);

Adding two collections of dice

use one_d_six::Dice;

let one_d6: Dice = "1d6".parse().unwrap();
let three_d4 = Dice::new(3, 4);

let dice = one_d6 + three_d4;

assert!(dice.total() >= 4);
assert!(dice.total() <= 18);

Methods

impl<T: Rollable> Dice<T>[src]

pub fn new(dice: usize, faces: T) -> Self[src]

Creates a new set of dice. Each die in the set has an initial starting value. Only allows dice of same type. No mixture of d4 and d6.

Example

use one_d_six::Dice;

// Creates 3d6 dice collection
let dice = Dice::new(3, 6);

pub fn from(dice: Box<[Die<T>]>) -> Self[src]

Creates a set of dice from a Vec<Die>. Allows for mixture of Die types (d4, d6, etc.).

Example

use one_d_six::{
    Dice,
    Die,
};

// Creates 2d6 + 1d4 dice collection
let dice = {
    let dice = [
        Die::new(6),
        Die::new(6),
        Die::new(4),
    ];
    Dice::from(Box::new(dice))
};

pub fn current_faces(&self) -> Vec<T>[src]

Gets the current face of each die in the dice set.

Example

use one_d_six::Dice;

let four_coins = Dice::new(4, 2);

for val in four_coins.current_faces().iter() {
    assert!(val == &1 || val == &2);
}

pub fn roll_all(&mut self) -> &Self[src]

Rolls all dice and returns self.

Example

use one_d_six::Dice;

let mut ten_d_4 = Dice::new(10, 4);

for val in ten_d_4.roll_all().current_faces().iter() {
    let val: u32 = *val;
    assert!(val >= 1);
    assert!(val <= 4);
}

pub fn total(&self) -> T where
    T: DiceTotal<T>, 
[src]

Gets the total of the current faces of the dice.

Example

use one_d_six::Dice;

let two_d_4 = Dice::new(2, 4);

assert!(two_d_4.total() >= 2);
assert!(two_d_4.total() <= 8);

Trait Implementations

impl<T: Rollable> Display for Dice<T> where
    T: DiceTotal<T>,
    T: Display
[src]

impl<T: Rollable> Debug for Dice<T> where
    T: Display
[src]

impl<T: Rollable> FromStr for Dice<T> where
    T: FromStr
[src]

type Err = String

The associated error which can be returned from parsing.

impl<T: Rollable> Add<Dice<T>> for Dice<T>[src]

type Output = Self

The resulting type after applying the + operator.

Auto Trait Implementations

impl<T> Send for Dice<T> where
    T: Send

impl<T> Unpin for Dice<T> where
    T: Unpin

impl<T> Sync for Dice<T> where
    T: Sync

impl<T> UnwindSafe for Dice<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for Dice<T> where
    T: RefUnwindSafe

Blanket Implementations

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

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

impl<T> ToString for T where
    T: Display + ?Sized
[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.

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

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

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

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,