simple-shunting 0.1.2

A simplified shunting library for evaluating math expressions in cosmwasm
Documentation
  • Coverage
  • 0%
    0 out of 7 items documented0 out of 0 items with examples
  • Size
  • Source code size: 43.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.25 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cowboy0015

Documentation

Simplified shunting library for evaluating math expressions in cosmwasm smart contracts. The original crate https://crates.io/crates/shunting could not be used directly for cosmwasm (rand library can not be used directly for wasm-unknonw-unknown target).

Using the library

fn main() {
  let input = "sin(0.2)^2 + cos(0.2)^2";
  let expr = ShuntingParser::parse_str(input).unwrap();
  let result = MathContext::new().eval(&expr).unwrap();
  println!("{} = {}", expr, result);
}

A MathContext

MathContext allows keeping context across multiple invocations to parse and evaluate. You can do this via the setvar method.

The tool in the crate

The crate also ship with the tox binary with a math repl.

$ tox
>> 4!
24
>> a = sin(0.2)^2 + cos(0.2)^2
>> a
1
>> (-3)!
NaN
>> (84 % (5/2)) !
1.32934
>> pi * 2.1^2 / cbrt(-(6+3))
-6.660512