pub struct Roll {
    pub number_of_sides: u16,
    pub number_of_dice: u16,
    pub modifier: i32,
}
Expand description

Holds information about a die roll.

Fields

number_of_sides: u16

The type of die.

number_of_dice: u16

How many dice are to be rolled.

modifier: i32

A modifier to be added to the result of the die rolls.

Implementations

A convenience function that allows you to manually create a new Roll.

Tries to parse input as roll notation (e.g. 4d20 + 5).

  • Whitespaces are ignored.
  • Checks for validity of roll.1
    • Enforces a limit of 100 dice per roll.2
Examples
use die_parser::Roll;
use die_parser::RollError;

let roll = Roll::parse_roll("3d10 - 5");
assert_eq!(roll, Ok(Roll::new(10, 3, -5)));

let invalid_roll = Roll::parse_roll("101d20");
assert_eq!(invalid_roll, Err(RollError::DiceExceedLimit));

  1. Valid die types are: d2, d4, d6, d8, d10, d12, d20, d100 

  2. If you wish to allow more (or only allow less) than 100 dice per roll, use Roll::parse_roll_with_limit() instead. 

Tries to parse input as roll notation (e.g. 4d20 + 5).

  • Whitespaces are ignored.
  • Checks for validity of roll.1
    • Enforces a custom limit of how many dice are allowed per roll (0 = no limit).
Examples
use die_parser::Roll;
use die_parser::RollError;

let roll = Roll::parse_roll_with_limit("3d10 - 5", 1000);
assert_eq!(roll, Ok(Roll::new(10, 3, -5)));

let invalid_roll = Roll::parse_roll_with_limit("15d20", 10);
assert_eq!(invalid_roll, Err(RollError::DiceExceedLimit));

  1. Valid die types are: d2, d4, d6, d8, d10, d12, d20, d100 

Trait Implementations

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.