rollr 0.2.0

A lightweight CLI tool and Rust library to roll RPG dice (e.g. 2D20) or flip a coin.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use rollr::{dices, throw::{flip_coin, throw_dices}};
use std::env;

fn main() {
  let args: Vec<String> = env::args().collect();

  match args.get(1).map(|s| s.to_ascii_lowercase()) {
    Some(s) if ["f", "flip", "flipcoin"].contains(&s.as_str()) => {
      let result = flip_coin();
      println!("🪙 {} !", if result { "Pile" } else { "Face" });
    }
    _ => {
      let roll: dices::DiceRoll = dices::parse_dice_arg(&args);
      let results: Vec<u16> = throw_dices(roll.count, roll.dice_type.value());
      println!("{}D{} : {:?}", roll.count, roll.dice_type.value(), results);
    }
  }
}