Crate rollz[][src]

rollz is a super-simple Rust crate that allows you to… roll dice! What else would you need from a crate?!

This crate implements standard D&D dice set: D4, D6, D8, D10, D12 and D20.

Here’s an example:

use rollz::prelude::*;
use rollz::D10;

let d: D10 = roll();
assert!((1..=10).contains(&d.val()));

You can also implement your own custom die if you implement the Rollable trait:

use rollz::prelude::*;

struct Fake100(u8);

impl Rollable for Fake100 {
    fn roll() -> Fake100 {
        Fake100 { 0: 100 }
    }
    fn val(&self) -> u8 {
        self.0
    }
}

let d: Fake100 = roll();
assert_eq!(100, d.val());

Modules

prelude

Structs

D4

A D4 die (4 faces): a roll will give you a u8 in the 1..=4 range.

D6

A D6 die (6 faces): a roll will give you a u8 in the 1..=6 range.

D8

A D8 die (8 faces): a roll will give you a u8 in the 1..=8 range.

D10

A D10 die (10 faces): a roll will give you a u8 in the 1..=10 range.

D12

A D12 die (12 faces): a roll will give you a u8 in the 1..=12 range.

D20

A D20 die (20 faces): a roll will give you a u8 in the 1..=20 range.

Traits

Rollable

This is the trait that every die needs to implement to be… well… “rollable”, right?

Functions

roll

A generic function to roll a given die. It uses return type polymorphism so it will roll the die you actually want! Boom, like magic!