fix: format and run cargo fix

This commit is contained in:
Charles
2024-11-26 21:36:19 -08:00
parent 8ca8a586b4
commit 5a34fe3d93
2 changed files with 17 additions and 13 deletions
+12 -8
View File
@@ -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; use rand::Rng;
#[derive(Debug)] #[derive(Debug)]
@@ -17,7 +22,7 @@ impl<const S: usize> Buckets<S> {
let max = roller.max(); let max = roller.max();
// Divide the number of buckets we have to work with by the range // Divide the number of buckets we have to work with by the range
// Store the step size // 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 _offsets = [0; S];
let mut cur = min; let mut cur = min;
for val in _offsets.iter_mut() { for val in _offsets.iter_mut() {
@@ -36,7 +41,7 @@ impl<const S: usize> Buckets<S> {
if pp == self._buckets.len() { if pp == self._buckets.len() {
// This value was beyond the last bucket; go ahead and store if in the // This value was beyond the last bucket; go ahead and store if in the
// last bucket // last bucket
pp = self.buckets().len()-1; pp = self.buckets().len() - 1;
} }
self._buckets[pp] += 1; self._buckets[pp] += 1;
} }
@@ -69,7 +74,7 @@ impl<const S: usize> Roller<S> {
while expr.len() > 0 { while expr.len() > 0 {
let (e, term) = term(expr)?; let (e, term) = term(expr)?;
expr = e; expr = e;
exprs[i] = Some(Cmd{term, oper: op}); exprs[i] = Some(Cmd { term, oper: op });
i += 1; i += 1;
if i == exprs.len() { if i == exprs.len() {
return Err(nom::Err::Incomplete(nom::Needed::new(S + 1))); return Err(nom::Err::Incomplete(nom::Needed::new(S + 1)));
@@ -86,7 +91,7 @@ impl<const S: usize> Roller<S> {
expr = e; expr = e;
} }
} }
Ok(Roller{exprs}) Ok(Roller { exprs })
} }
pub fn roll<R: Rng>(&self, rng: &mut R) -> i64 { pub fn roll<R: Rng>(&self, rng: &mut R) -> i64 {
let mut sum = 0; let mut sum = 0;
@@ -173,7 +178,7 @@ enum Oper {
Sub, Sub,
} }
pub struct Roll{ pub struct Roll {
reps: u64, reps: u64,
dice: u64, dice: u64,
} }
@@ -198,7 +203,6 @@ impl Roll {
} }
} }
fn term(e: &str) -> IResult<&str, Term> { fn term(e: &str) -> IResult<&str, Term> {
// Ignore whitespace // Ignore whitespace
let (e, _) = multispace0(e)?; let (e, _) = multispace0(e)?;
@@ -213,7 +217,7 @@ fn roll(mut e: &str) -> IResult<&str, Term> {
} }
let (e, _) = complete::char('d')(e)?; let (e, _) = complete::char('d')(e)?;
let (e, dice) = complete::u64(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> { fn cnst(e: &str) -> IResult<&str, Term> {
+2 -2
View File
@@ -1,6 +1,6 @@
use rand::thread_rng; use rand::thread_rng;
use std::io::{self, BufRead, Write};
use rust_roller::{Buckets, Roller}; use rust_roller::{Buckets, Roller};
use std::io::{self, BufRead, Write};
use textplots::{Chart, Plot, Shape}; use textplots::{Chart, Plot, Shape};
fn main() { fn main() {
@@ -14,7 +14,7 @@ fn main() {
Err(e) => { Err(e) => {
println!("bad input; err: {}", e); println!("bad input; err: {}", e);
continue; continue;
}, }
}; };
let mut bins = Buckets::<180>::new(&roller); let mut bins = Buckets::<180>::new(&roller);