This repository has been archived on 2024-07-25. You can view files and clone it, but cannot push or open issues or pull requests.
estring/examples/calc.rs

14 lines
314 B
Rust
Raw Normal View History

2022-07-28 13:09:09 +03:00
use estring::{Aggregate, EString, Product, SepVec, Sum};
2022-07-24 02:23:19 +03:00
type PlusVec<T> = SepVec<T, '+'>;
type MulVec<T> = SepVec<T, '*'>;
2022-07-26 18:14:26 +03:00
fn main() -> estring::Result<()> {
2022-07-24 02:23:19 +03:00
let res = EString::from("10+5*2+3")
2022-07-28 13:09:09 +03:00
.parse::<Sum<PlusVec<Product<MulVec<f32>>>>>()?
.agg();
2022-07-24 02:23:19 +03:00
assert_eq!(res, 23.0);
Ok(())
}