pub struct DiceRoll {
pub rolls: u32,
pub sides: u32,
}
Expand description
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§
Source§impl DiceRoll
impl DiceRoll
Sourcepub const MINIMUM_ROLLS: u32 = 1u32
pub const MINIMUM_ROLLS: u32 = 1u32
All dice must be rollable at least once.
Sourcepub const MINIMUM_SIDES: u32 = 2u32
pub const MINIMUM_SIDES: u32 = 2u32
All dice must have at least 2 sides.
Sourcepub fn from_string(string: &str) -> Result<Self>
pub fn from_string(string: &str) -> Result<Self>
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()
Sourcepub fn parse_rolls_and_sides(string: &str) -> Result<(u32, u32)>
pub fn parse_rolls_and_sides(string: &str) -> Result<(u32, u32)>
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
Auto Trait Implementations§
impl Freeze for DiceRoll
impl RefUnwindSafe for DiceRoll
impl Send for DiceRoll
impl Sync for DiceRoll
impl Unpin for DiceRoll
impl UnwindSafe for DiceRoll
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