Skip to content

Commit

Permalink
Rename max_rolls parameters to list_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gawdl3y committed Mar 18, 2024
1 parent a2eb0ff commit 95b8123
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/dice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ impl Describe for Rolled<'_> {
/// Builds a string of the dice expression the roll is from and a list of all of the individual rolled dice
/// (see [`DieRoll::fmt()`]).
///
/// If `max_rolls` is specified and there are more rolls than it, the output will be truncated and appended with
/// If `list_limit` is specified and there are more rolls than it, the output will be truncated and appended with
/// "X more..." (where X is the remaining roll count past the max).
///
/// # Examples
Expand Down Expand Up @@ -585,17 +585,17 @@ impl Describe for Rolled<'_> {
/// ```
///
/// [`DieRoll::fmt()`]: ./struct.DieRoll.html#method.fmt
fn describe(&self, max_rolls: Option<usize>) -> String {
let max_rolls = max_rolls.unwrap_or(usize::MAX);
fn describe(&self, list_limit: Option<usize>) -> String {
let list_limit = list_limit.unwrap_or(usize::MAX);
let total_rolls = self.rolls.len();
let truncated_rolls = total_rolls.saturating_sub(max_rolls);
let truncated_rolls = total_rolls.saturating_sub(list_limit);

format!(
"{}[{}{}]",
self.dice,
self.rolls
.iter()
.take(max_rolls)
.take(list_limit)
.map(|r| r.to_string())
.collect::<Vec<_>>()
.join(", "),
Expand Down
36 changes: 18 additions & 18 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ impl Describe for Term {
/// operations could be considered ambiguous, such as when mixing addition and multiplication together. All strings
/// output from this should result in the exact same Term layout when re-parsing them.
///
/// `max_rolls` does not affect the output of this implementation in any way since there are no possible lists of
/// `list_limit` does not affect the output of this implementation in any way since there are no possible lists of
/// elements included, so it is always safe to pass `None`.
#[inline]
fn describe(&self, _max_rolls: Option<usize>) -> String {
fn describe(&self, _list_limit: Option<usize>) -> String {
match self {
Self::Num(x) => x.to_string(),
Self::Dice(dice) => dice.to_string(),
Expand Down Expand Up @@ -203,21 +203,21 @@ impl EvaledTerm<'_> {
}

impl Describe for EvaledTerm<'_> {
fn describe(&self, max_rolls: Option<usize>) -> String {
fn describe(&self, list_limit: Option<usize>) -> String {
match self {
Self::Num(x) => x.to_string(),
Self::Dice(roll) => roll.describe(max_rolls),
Self::Dice(roll) => roll.describe(list_limit),

Self::Neg(x) => match x.as_ref() {
Self::Num(..) | Self::Dice(..) => format!("-{}", x.describe(max_rolls)),
_ => format!("-({})", x.describe(max_rolls)),
Self::Num(..) | Self::Dice(..) => format!("-{}", x.describe(list_limit)),
_ => format!("-({})", x.describe(list_limit)),
},

Self::Add(a, b) => self.describe_binary_term('+', a.as_ref(), b.as_ref(), max_rolls),
Self::Sub(a, b) => self.describe_binary_term('-', a.as_ref(), b.as_ref(), max_rolls),
Self::Mul(a, b) => self.describe_binary_term('*', a.as_ref(), b.as_ref(), max_rolls),
Self::DivDown(a, b) => self.describe_binary_term('/', a.as_ref(), b.as_ref(), max_rolls),
Self::DivUp(a, b) => self.describe_binary_term('\\', a.as_ref(), b.as_ref(), max_rolls),
Self::Add(a, b) => self.describe_binary_term('+', a.as_ref(), b.as_ref(), list_limit),
Self::Sub(a, b) => self.describe_binary_term('-', a.as_ref(), b.as_ref(), list_limit),
Self::Mul(a, b) => self.describe_binary_term('*', a.as_ref(), b.as_ref(), list_limit),
Self::DivDown(a, b) => self.describe_binary_term('/', a.as_ref(), b.as_ref(), list_limit),
Self::DivUp(a, b) => self.describe_binary_term('\\', a.as_ref(), b.as_ref(), list_limit),
}
}
}
Expand Down Expand Up @@ -288,8 +288,8 @@ pub trait HasTermType {
pub trait Describe {
/// Builds a detailed expression string with additional information about non-deterministic elements.
/// Any elements of the expression that can have a different result between multiple evaluations or multiple results
/// should list all of the specific individual results that occurred (ideally, up to `max_rolls` of them).
fn describe(&self, max_rolls: Option<usize>) -> String;
/// should list all of the specific individual results that occurred (ideally, up to `list_limit` of them).
fn describe(&self, list_limit: Option<usize>) -> String;
}

/// Trait for describing binary expressions with influence from own type.
Expand All @@ -302,7 +302,7 @@ trait DescribeBinaryTerm: HasTermType + Describe {
op: char,
a: &impl DescribeBinaryTerm,
b: &impl DescribeBinaryTerm,
max_rolls: Option<usize>,
list_limit: Option<usize>,
) -> String {
format!(
"{} {} {}",
Expand All @@ -311,17 +311,17 @@ trait DescribeBinaryTerm: HasTermType + Describe {
| (TermType::Multiplicative, TermType::Additive)
| (TermType::Unary, TermType::Additive)
| (TermType::Unary, TermType::Multiplicative)
| (TermType::Unary, TermType::Unary) => paren_wrap(a.describe(max_rolls)),
_ => a.describe(max_rolls),
| (TermType::Unary, TermType::Unary) => paren_wrap(a.describe(list_limit)),
_ => a.describe(list_limit),
},
op,
match (self.term_type(), b.term_type()) {
(TermType::Additive, TermType::Multiplicative)
| (TermType::Multiplicative, TermType::Additive)
| (TermType::Unary, TermType::Additive)
| (TermType::Unary, TermType::Multiplicative)
| (TermType::Unary, TermType::Unary) => paren_wrap(b.describe(max_rolls)),
_ => b.describe(max_rolls),
| (TermType::Unary, TermType::Unary) => paren_wrap(b.describe(list_limit)),
_ => b.describe(list_limit),
}
)
}
Expand Down

0 comments on commit 95b8123

Please sign in to comment.