pub struct Dice<T: Rollable = u32> { /* private fields */ }Expand description
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);Implementations§
Source§impl<T: Rollable> Dice<T>
impl<T: Rollable> Dice<T>
Sourcepub fn new(dice: usize, faces: T) -> Self
pub fn new(dice: usize, faces: T) -> Self
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);Sourcepub fn from(dice: Box<[Die<T>]>) -> Self
pub fn from(dice: Box<[Die<T>]>) -> Self
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))
};Sourcepub fn current_faces(&self) -> Vec<T>
pub fn current_faces(&self) -> Vec<T>
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);
}Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Dice<T>
impl<T> RefUnwindSafe for Dice<T>where
T: RefUnwindSafe,
impl<T> Send for Dice<T>where
T: Send,
impl<T> Sync for Dice<T>where
T: Sync,
impl<T> Unpin for Dice<T>where
T: Unpin,
impl<T> UnwindSafe for Dice<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more