[−][src]Struct dicelib::dice::DiceRoll
A dice roll expressed in RPG term e.g. 3d6 means "roll a 6-sided die 3 times".
Fields
rolls: u32
How many times the dice will be rolled.
sides: u32
The maximum number of sides the dice has. If it has 6 sides, the most it can roll for at any one time is 6.
Implementations
impl DiceRoll
[src]
pub const MINIMUM_ROLLS: u32
[src]
All dice must be rollable at least once.
pub const MINIMUM_SIDES: u32
[src]
All dice must have at least 2 sides.
pub fn new(rolls: u32, sides: u32) -> Result<Self>
[src]
pub fn from_string(string: &str) -> Result<Self>
[src]
Create a DiceRoll
from a string.
use dicelib::dice::DiceRoll; let dice = DiceRoll::from_string(&"3d6".to_string()).unwrap();
Errors
- See
parse_rolls_and_sides()
pub fn parse_rolls_and_sides(string: &str) -> Result<(u32, u32)>
[src]
Utility function to parse the rolls and sides of a dice roll string
into a pair of u32s. If you want a DiceRoll
, use from_string()
instead.
use dicelib::dice::DiceRoll; let (rolls, sides) = DiceRoll::parse_rolls_and_sides(&"1d4".to_string()).unwrap();
Errors
- If rolls or sides cannot be matched (expression is malformed)
- If the matched rolls and sides are not parseable as
u32
pub fn roll(&self, rng: &mut impl RngCore) -> Result<u32>
[src]
Performs the DiceRoll
and returns the sum of all rolls.
Errors
IntegerOverFlow
if the rolls and sides are very, very big numbers.
Auto Trait Implementations
impl RefUnwindSafe for DiceRoll
impl Send for DiceRoll
impl Sync for DiceRoll
impl Unpin for DiceRoll
impl UnwindSafe for DiceRoll
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> 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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,