pub struct Dice { /* private fields */ }Expand description
Represents a set of dice and rules for calculating their value when rolled
Implementations§
Source§impl Dice
impl Dice
Sourcepub fn new<S: AsRef<str>>(s: S) -> Self
pub fn new<S: AsRef<str>>(s: S) -> Self
Create a new Dice with the given dice specification. The specification is as follows:
[mul*]<rolls>d<faces>[+/-offset], where
rollsnumber of dice is thrown,- these dice have
facesnumber of faces, - once all the dice have been thrown,
offsetis added to their value, - and finally, that number is multiplied by
mul.
§Example
let dice = Dice::new("5*3d6+2");Sourcepub fn roll<R: Rng>(&self, mersenne: &mut R) -> i32
pub fn roll<R: Rng>(&self, mersenne: &mut R) -> i32
Roll the dice according to their parameters. See the documentation of new() for how these
parameters get used.
Sourcepub fn single_roll<R: Rng, S: AsRef<str>>(mersenne: &mut R, s: S) -> i32
pub fn single_roll<R: Rng, S: AsRef<str>>(mersenne: &mut R, s: S) -> i32
Create a Dice and roll these dice once according to the given dice specification. See the
documentation of new() for how this specification works. If you intend to use this dice
set more than once, it’s generally better to store the Dice instance and call roll()
rather than to call this method over and over.
Trait Implementations§
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