[][src]Crate one_d_six

Provides utilities for rolling dice.

Examples

Simple Usage

use one_d_six::quickroll;

if quickroll::<u16>("1d2") == 1 {
    println!("Heads!");
} else {
    println!("Tails!");
}

Adding Sets of Dice Together

use one_d_six::Dice;

// 3d6
let set_1 = Dice::new(3, 6);
// 2d4
let set_2: Dice = "2d4".parse().unwrap();

// 3d6 + 2d4
let dice = set_1 + set_2;

// Each set of dice starts pre-rolled
let roll = dice.total();

println!("Result of 3d6 + 2d4 roll: {}", roll);

Getting Dice as String

Simple String

use one_d_six::Dice;


let dice: Dice = Dice::new(3, 6);
println!("3d6: {}", dice);

Complex String

use one_d_six::Dice;


// Will look like "1 2 3"
let dice = Dice::new(3, 6);
println!("3d6: {:?}", dice);

Structs

Dice

A Handful of dice.

Die

Represents a single die. Has an initial random value.

Traits

DiceTotal

Allows one_d_six::Dice::total to be used.

Rollable

Defines a type that can be rolled for. Implement this trait on a type you would like to roll for.

Functions

quickroll

Rolls dice based on a 1d6 style string.

try_quickroll

Attempts to roll dice based on a 1d6 style string.