[][src]Trait one_d_six::Rollable

pub trait Rollable: Copy {
    fn roll(max: Self) -> Self;
}

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

Example

use one_d_six::{
    Die,
    Rollable,
    quickroll,
};

#[derive(Clone, Copy, Debug)]
enum Shapes {
    Triangle,
    Square,
    Circle,
}

impl Rollable for Shapes {
    // We're ignoring max since we don't need a maximum for this example
    fn roll(_max: Shapes) -> Shapes {
        let roll_result: u8 = quickroll("1d3");
        match roll_result {
            1 => Shapes::Triangle,
            2 => Shapes::Square,
            3 => Shapes::Circle,
            _ => unreachable!(),
        }
    }
}

// We still need a maximum to satisfy Rollable::roll requirements
let max = Shapes::Circle;
let mut shape_roller = Die::new(max);
println!("You rolled {:?}!", shape_roller.roll());

Required methods

fn roll(max: Self) -> Self

Loading content...

Implementations on Foreign Types

impl Rollable for u8[src]

impl Rollable for u16[src]

impl Rollable for u32[src]

impl Rollable for u64[src]

impl Rollable for u128[src]

impl Rollable for usize[src]

impl Rollable for i8[src]

impl Rollable for i16[src]

impl Rollable for i32[src]

impl Rollable for i64[src]

impl Rollable for i128[src]

impl Rollable for isize[src]

Loading content...

Implementors

Loading content...