summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs33
-rw-r--r--src/dice.rs25
-rw-r--r--src/main.rs6
-rw-r--r--src/random_tables.rs8
4 files changed, 37 insertions, 35 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 05256f3..226b06a 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,4 +1,4 @@
-use clap::{arg, Command, crate_authors, crate_description, crate_name, crate_version};
+use clap::{arg, crate_authors, crate_description, crate_name, crate_version, Command};
pub fn cli() -> Command {
Command::new(crate_name!())
@@ -8,22 +8,23 @@ pub fn cli() -> Command {
.subcommand_required(true)
.arg_required_else_help(true)
.allow_external_subcommands(true)
- .subcommand(Command::new("random")
- .about("Generates a random something")
- .args_conflicts_with_subcommands(true)
- .subcommand(Command::new("henchman")
- .about("Generates a random henchman"))
- .subcommand(Command::new("magic")
- .about("Generates a magic item")),
+ .subcommand(
+ Command::new("random")
+ .about("Generates a random something")
+ .args_conflicts_with_subcommands(true)
+ .subcommand(Command::new("henchman").about("Generates a random henchman"))
+ .subcommand(Command::new("magic").about("Generates a magic item")),
)
- .subcommand(Command::new("roll")
- .about("Rolls dice based on a given formula")
- .arg(arg!(<FORMULA> "The dice rolling formula"))
- .arg_required_else_help(true),
+ .subcommand(
+ Command::new("roll")
+ .about("Rolls dice based on a given formula")
+ .arg(arg!(<FORMULA> "The dice rolling formula"))
+ .arg_required_else_help(true),
)
- .subcommand(Command::new("table")
- .about("Rolls on a random table")
- .arg(arg!(<TABLE> "The name of the table to roll on"))
- .arg_required_else_help(true),
+ .subcommand(
+ Command::new("table")
+ .about("Rolls on a random table")
+ .arg(arg!(<TABLE> "The name of the table to roll on"))
+ .arg_required_else_help(true),
)
}
diff --git a/src/dice.rs b/src/dice.rs
index 64a4635..2c778f4 100644
--- a/src/dice.rs
+++ b/src/dice.rs
@@ -1,6 +1,6 @@
+use rand::Rng;
use std::fmt;
use std::fmt::Formatter;
-use rand::Rng;
pub struct DieRoll {
sides: u32,
@@ -9,10 +9,7 @@ pub struct DieRoll {
impl DieRoll {
fn new(sides: u32, face: u32) -> Self {
- DieRoll {
- sides,
- face,
- }
+ DieRoll { sides, face }
}
}
@@ -22,9 +19,7 @@ pub struct RollResult {
impl RollResult {
pub fn new() -> Self {
- RollResult {
- rolls: Vec::new(),
- }
+ RollResult { rolls: Vec::new() }
}
fn add_roll(&mut self, roll: DieRoll) {
@@ -38,10 +33,16 @@ impl RollResult {
impl fmt::Display for RollResult {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
- write!(f, "{} ({})", self.total(), self.rolls.iter()
- .map(|dr| dr.face.to_string())
- .collect::<Vec<String>>()
- .join(", "))
+ write!(
+ f,
+ "{} ({})",
+ self.total(),
+ self.rolls
+ .iter()
+ .map(|dr| dr.face.to_string())
+ .collect::<Vec<String>>()
+ .join(", ")
+ )
}
}
diff --git a/src/main.rs b/src/main.rs
index b63d799..f9fb6bd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -22,14 +22,14 @@ fn main() {
let magic = random_tables.roll_table("ua_magic");
println!("{}", magic);
}
- _ => unreachable!()
+ _ => unreachable!(),
}
}
Some(("roll", sub_matches)) => {
let formula = sub_matches.get_one::<String>("FORMULA").expect("required");
match dice::roll_formula(formula) {
Some(roll_result) => println!("Rolled: {}", roll_result),
- None => eprintln!("Error: Invalid roll formula or calculation failed.")
+ None => eprintln!("Error: Invalid roll formula or calculation failed."),
}
}
Some(("table", sub_matches)) => {
@@ -37,6 +37,6 @@ fn main() {
let output_text = random_tables.roll_table(table_name);
println!("{}", output_text)
}
- _ => unreachable!()
+ _ => unreachable!(),
}
}
diff --git a/src/random_tables.rs b/src/random_tables.rs
index f949554..8bc1e61 100644
--- a/src/random_tables.rs
+++ b/src/random_tables.rs
@@ -1,10 +1,10 @@
+use crate::dice;
+use include_dir::{include_dir, Dir};
use serde::Deserialize;
use serde_yaml;
use std::collections::HashMap;
use std::error::Error;
use std::string::String;
-use include_dir::{include_dir, Dir};
-use crate::dice;
#[derive(Debug, Deserialize)]
struct RandomTable {
@@ -28,7 +28,7 @@ pub struct RandomTables {
tables: HashMap<String, RandomTable>,
}
-const YAML_DIR : Dir = include_dir!("src/data/random_tables/");
+const YAML_DIR: Dir = include_dir!("src/data/random_tables/");
impl RandomTables {
pub fn new() -> Result<Self, Box<dyn Error>> {
@@ -99,7 +99,7 @@ impl RandomTables {
None
}
}
- _ => None
+ _ => None,
}
}
}