From f8c97b6965b42768fad42e1a1ef70fe89a8082f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 24 Jul 2022 02:23:19 +0300 Subject: [PATCH] example: add calc example from readme --- Cargo.toml | 4 ++++ examples/calc.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 examples/calc.rs diff --git a/Cargo.toml b/Cargo.toml index 968f451..3713155 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,3 +30,7 @@ vec = [] [badges] maintenance = { status = "actively-developed" } + +[[example]] +name = "calc" +required-features = ["vec", "number"] diff --git a/examples/calc.rs b/examples/calc.rs new file mode 100644 index 0000000..27ea9e4 --- /dev/null +++ b/examples/calc.rs @@ -0,0 +1,15 @@ +use estring::{EString, SepVec}; + +type PlusVec = SepVec; +type MulVec = SepVec; + +fn main() -> Result<(), estring::ParseError> { + let res = EString::from("10+5*2+3") + .parse::>>()? + .iter() + .map(|m| m.iter().product::()) + .sum::(); + + assert_eq!(res, 23.0); + Ok(()) +}