#[non_exhaustive]pub enum Expr {
Num(i32),
Dice(Dice),
Neg(Box<Self>),
Add(Box<Self>, Box<Self>),
Sub(Box<Self>, Box<Self>),
Mul(Box<Self>, Box<Self>),
DivDown(Box<Self>, Box<Self>),
DivUp(Box<Self>, Box<Self>),
}
Expand description
Tree structure of individual elements of a full mathematical dice expression
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Num(i32)
Standalone integer
Dice(Dice)
Dice literal
Neg(Box<Self>)
Negation of an expression (makes the result of it negative)
Add(Box<Self>, Box<Self>)
Sum of two expressions
Sub(Box<Self>, Box<Self>)
Difference of two expressions
Mul(Box<Self>, Box<Self>)
Product of two expressions
DivDown(Box<Self>, Box<Self>)
Integer quotient of two expressions (rounded down)
DivUp(Box<Self>, Box<Self>)
Integer quotient of two expressions (rounded up)
Implementations§
source§impl Expr
impl Expr
sourcepub fn eval(&self, rng: &mut impl Roller) -> Result<Evaled<'_>, EvalError>
pub fn eval(&self, rng: &mut impl Roller) -> Result<Evaled<'_>, EvalError>
Evaluates the expression. For most types of expressions, this will directly result in a 1:1 equivalent
Evaled
, with the notable exception of Expr::Dice
. For dice expressions, the dice they contain are
rolled, resulting in an Evaled::Dice
with the Rolled
set of dice.
§Errors
If there is an integer overflow or division error encountered during any operations, or if an error occurs during dice rolling, an error variant will be returned.
sourcepub fn is_deterministic(&self) -> bool
pub fn is_deterministic(&self) -> bool
Checks whether the expression is deterministic (will always yield the same value with every evaluation).
A Self::Num
will always return true
, a Self::Dice
will always return false
unless the dice they
contain only have one side, and all unary and binary expressions forward the check to their children.
Trait Implementations§
source§impl Describe for Expr
impl Describe for Expr
source§fn describe(&self, _list_limit: Option<usize>) -> String
fn describe(&self, _list_limit: Option<usize>) -> String
Builds a full usable expression string from the expressions. Operations are grouped with parentheses whenever the order of operations could be considered ambiguous, such as when mixing addition and multiplication together. All strings output from this should result in the exact same expression tree when re-parsing them.
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
.
source§impl GenParser<Expr> for Expr
impl GenParser<Expr> for Expr
source§impl HasOpType for Expr
impl HasOpType for Expr
source§fn is_additive(&self) -> bool
fn is_additive(&self) -> bool
source§fn is_multiplicative(&self) -> bool
fn is_multiplicative(&self) -> bool
source§impl PartialEq for Expr
impl PartialEq for Expr
impl Eq for Expr
impl StructuralPartialEq for Expr
Auto Trait Implementations§
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnwindSafe for Expr
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef
].