fix: format and run cargo fix
This commit is contained in:
+15
-11
@@ -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<const S: usize> Buckets<S> {
|
||||
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<const S: usize> Buckets<S> {
|
||||
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<const S: usize> Roller<S> {
|
||||
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<const S: usize> Roller<S> {
|
||||
expr = e;
|
||||
}
|
||||
}
|
||||
Ok(Roller{exprs})
|
||||
Ok(Roller { exprs })
|
||||
}
|
||||
pub fn roll<R: Rng>(&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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user