rollz 0.1.1

A super-simple Rust crate that allows you to... roll dice! What else would you need from a crate?
Documentation

rollz 🎲

build badge codecov crates.io badge Documentation

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

In reality, this crate was born as an experiment for me to understand Rust return type polymorphism and while I was at it, why wouldn't I publish it as a crate for everyone else enjoyment!?

I don't expect this to be particularly useful for real life projects™️, except maybe if you are implementing something that has to do with D&D or similar types of board games.

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

Install

To install the library add the following lines to your Cargo.toml:

[dependencies]
rollz = "0"

Or, if you have cargo add, you can run the following command:

cargo add rollz@0

Sample Usage

This is how you would roll a D10 with rollz:

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

fn main() {
    let d: D10 = roll();
    println!("You got a {}", d.val()); // You got a 2
}

Or you can also roll multiple dices together, because why not?

use rollz::prelude::*;
use rollz::D6;

fn main() {
    let d: (D6, D6) = (roll(), roll());
    println!("You got {:?}", d); // You got (D6(4), D6(6))
}

More usage examples are available in the examples folder.

Create your own custom die

Here's an example for you, if you want to build a custom die:

use rollz::prelude::*;

/// A roll of this guy will always give you 100!
/// Shush ... Don't tell anyone! 🤫
#[derive(Debug)]
struct Fake100(u8);

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

fn main() {
    println!("I bet I'll get a 100 this time!");
    let d: Fake100 = roll();
    println!("Look what I got: {}!", d.val())
}

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.

License

Licensed under MIT License. © Luciano Mammino.