Crates.io | expressions |
lib.rs | expressions |
version | 2.0.0 |
source | src |
created_at | 2023-03-15 22:05:53.489032 |
updated_at | 2023-09-23 13:08:38.702555 |
description | Flexible expression parser and evaluator |
homepage | |
repository | https://github.com/andreashgk/expressions/ |
max_upload_size | |
id | 811019 |
size | 54,186 |
A flexible expression parser and evaluator crate. Custom types in expressions are supported through a trait.
assert_eq!(expressions::eval::<i32>("2 ^ (3) ^ 1 + 4 - 3 * -2"), Ok(18));
By default, the Eval
trait is implemented on all integers and all floats. If these default implementations are not
desired, a new implementation can be made through a wrapper type.
Support for custom types can also be added by implementing Eval
for this type.
The default implementations use lazy evaluation for the boolean operators. Bitwise operations are not supported for floats, and will return an error when evaluated. Integers will return an error when there is overflow or a division by zero.
The following operators are currently supported:
==
Equals!=
Not equals>=
Greater than or equals>
Greater than<=
Less than or equals<
Less than&&
Boolean AND||
Boolean OR!
Boolean NOT (unary)&
Bitwise AND|
Bitwise OR~
Bitwise NOT (unary)+
Addition-
Subtraction*
Multiplication/
Division%
Modulo^
Exponentiation+
Plus (unary)-
Minus (unary)