Skip to main content

Crate lib_dice

Crate lib_dice 

Source
Expand description

A library for parcing dice rolls using nom.

§Usage

use lib_dice::DiceRoll;
use std::str::FromStr;

fn main() {
	let roll_1 = lib_dice::roll(1, 8, 0); // 1d8 + 0
	let roll_2 = lib_dice::roll_from_str("2d6 + 7").unwrap();

    let dice = DiceRoll::new(1, 8, 3); // 1d8 + 3
    let roll_3 = dice.roll();
    let dice = DiceRoll::from_str("1d12").unwrap();
    let roll_4 = dice.roll_no_bonus();
}

Structs§

DiceFormatError
DiceRoll
A single dice roll configuration including count, dice and bonus

Functions§

roll
Simulate a random dice roll using the rand crate.
roll_from_str
Parse a dice roll from a sting in one of the following formats