From 5a34fe3d938d6c8101ac2f90467a00655cf12727 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 26 Nov 2024 21:36:19 -0800 Subject: [PATCH] fix: format and run cargo fix --- src/lib.rs | 26 +++++++++++++++----------- src/main.rs | 4 ++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 94a96ca..695d744 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,9 @@ -use nom::{branch::alt, character::complete::{self, multispace0}, combinator::opt, IResult}; +use nom::{ + branch::alt, + character::complete::{self, multispace0}, + combinator::opt, + IResult, +}; use rand::Rng; #[derive(Debug)] @@ -17,7 +22,7 @@ impl Buckets { let max = roller.max(); // Divide the number of buckets we have to work with by the range // Store the step size - let step = ((max-min) as usize) / S + 1; + let step = ((max - min) as usize) / S + 1; let mut _offsets = [0; S]; let mut cur = min; for val in _offsets.iter_mut() { @@ -36,7 +41,7 @@ impl Buckets { if pp == self._buckets.len() { // This value was beyond the last bucket; go ahead and store if in the // last bucket - pp = self.buckets().len()-1; + pp = self.buckets().len() - 1; } self._buckets[pp] += 1; } @@ -69,7 +74,7 @@ impl Roller { while expr.len() > 0 { let (e, term) = term(expr)?; expr = e; - exprs[i] = Some(Cmd{term, oper: op}); + exprs[i] = Some(Cmd { term, oper: op }); i += 1; if i == exprs.len() { return Err(nom::Err::Incomplete(nom::Needed::new(S + 1))); @@ -86,7 +91,7 @@ impl Roller { expr = e; } } - Ok(Roller{exprs}) + Ok(Roller { exprs }) } pub fn roll(&self, rng: &mut R) -> i64 { let mut sum = 0; @@ -158,7 +163,7 @@ impl Term { Term::Roll(r) => r.min(), } } - + fn max(&self) -> u64 { match self { Term::Const(c) => *c, @@ -173,7 +178,7 @@ enum Oper { Sub, } -pub struct Roll{ +pub struct Roll { reps: u64, dice: u64, } @@ -198,12 +203,11 @@ impl Roll { } } - fn term(e: &str) -> IResult<&str, Term> { // Ignore whitespace let (e, _) = multispace0(e)?; alt((roll, cnst))(e) -} +} fn roll(mut e: &str) -> IResult<&str, Term> { let mut reps = 1; @@ -213,7 +217,7 @@ fn roll(mut e: &str) -> IResult<&str, Term> { } let (e, _) = complete::char('d')(e)?; let (e, dice) = complete::u64(e)?; - Ok((e, Term::Roll(Roll{reps, dice}))) + Ok((e, Term::Roll(Roll { reps, dice }))) } fn cnst(e: &str) -> IResult<&str, Term> { @@ -328,4 +332,4 @@ mod tests { assert_eq!(roller.min(), 4); assert_eq!(roller.max(), 21); } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 295f124..f64f78f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use rand::thread_rng; -use std::io::{self, BufRead, Write}; use rust_roller::{Buckets, Roller}; +use std::io::{self, BufRead, Write}; use textplots::{Chart, Plot, Shape}; fn main() { @@ -14,7 +14,7 @@ fn main() { Err(e) => { println!("bad input; err: {}", e); continue; - }, + } }; let mut bins = Buckets::<180>::new(&roller);