[][src]Struct dicelib::dice::DiceRoll

pub struct DiceRoll {
    pub rolls: u32,
    pub sides: u32,
}

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]

Create a DiceRoll.

Errors

  • rolls is less than 1
  • sides is less than 2

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,