[−][src]Struct one_d_six::Dice
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 = 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 = 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: 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 = 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
Vec<T>: DiceTotal<T>,
[src]
Vec<T>: DiceTotal<T>,
Gets the total of the current faces of the dice.
Example
use one_d_six::Dice; let two_d_4: Dice = 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
Vec<T>: DiceTotal<T>,
[src]
Vec<T>: DiceTotal<T>,
impl<T: Rollable> Debug for Dice<T>
[src]
impl<T: Rollable> Add<Dice<T>> for Dice<T>
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
impl<T: Rollable> FromStr for Dice<T>
[src]
Auto Trait Implementations
impl<T> Send for Dice<T> where
T: Send,
T: Send,
impl<T> Sync for Dice<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Dice<T> where
T: Unpin,
T: Unpin,
impl<T> RefUnwindSafe for Dice<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> UnwindSafe for Dice<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,