pub struct Dice {
pub number: u32,
pub sides: u32,
}Fields§
§number: u32§sides: u32Implementations§
Source§impl Dice
impl Dice
Sourcepub fn parse(dice: &str) -> Result<Dice, String>
pub fn parse(dice: &str) -> Result<Dice, String>
Create a Dice instance given a standard dice format.
Expected format is
let result = rolldice::Dice::parse("4d6").unwrap();
assert_eq!(result, rolldice::Dice { number: 4, sides: 6 });Sourcepub fn generate<R: Rng>(&self, rng: &mut R) -> u32
pub fn generate<R: Rng>(&self, rng: &mut R) -> u32
Generate a dice role from a Dice instance. Requires a random number generator from the “rand” crate to be passed in.
extern crate rand;
extern crate rolldice;
let dice = rolldice::Dice { number: 4, sides: 8 };
let mut rng = rand::thread_rng();
let result = dice.generate(&mut rng);Trait Implementations§
impl Eq for Dice
impl StructuralPartialEq for Dice
Auto Trait Implementations§
impl Freeze for Dice
impl RefUnwindSafe for Dice
impl Send for Dice
impl Sync for Dice
impl Unpin for Dice
impl UnwindSafe for Dice
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