pub enum Expr {
Int(i64),
Var(String),
Neg(Box<Expr>),
Add(Box<Expr>, Box<Expr>),
Sub(Box<Expr>, Box<Expr>),
Mul(Box<Expr>, Box<Expr>),
Pow(Box<Expr>, Box<Expr>),
}Expand description
A parsed safe-integer expression. Variables resolve against the scalar values chosen earlier in generation order.
Variants§
Int(i64)
Integer literal.
Var(String)
Variable reference (scalar name).
Neg(Box<Expr>)
-e.
Add(Box<Expr>, Box<Expr>)
a + b.
Sub(Box<Expr>, Box<Expr>)
a - b.
Mul(Box<Expr>, Box<Expr>)
a * b.
Pow(Box<Expr>, Box<Expr>)
a ^ b (non-negative integer exponent).
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn eval(&self, env: &BTreeMap<String, i64>) -> Result<i64, ExprError>
pub fn eval(&self, env: &BTreeMap<String, i64>) -> Result<i64, ExprError>
Evaluates against env (chosen scalar values). Fails on unknown
variables, non-integer/negative exponents, overflow, or results
outside the JS safe-integer range ac-test used.
§Errors
Returns a description when the expression cannot be evaluated to a safe integer.
Trait Implementations§
impl StructuralPartialEq for Expr
Auto Trait Implementations§
impl Forget for Expr
impl Freeze for Expr
impl Move for Expr
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnsafeUnpin for Exprwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const Expr is !null: UnsafeUnpin,
PhantomData<Expr>: UnsafeUnpin,
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
Mutably borrows from an owned value. Read more