Merge pull request #8 from pleshevskiy/examples
example: add calc example from readme
This commit is contained in:
commit
372f8af96c
2 changed files with 19 additions and 0 deletions
|
@ -30,3 +30,7 @@ vec = []
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "calc"
|
||||||
|
required-features = ["vec", "number"]
|
||||||
|
|
15
examples/calc.rs
Normal file
15
examples/calc.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
use estring::{EString, SepVec};
|
||||||
|
|
||||||
|
type PlusVec<T> = SepVec<T, '+'>;
|
||||||
|
type MulVec<T> = SepVec<T, '*'>;
|
||||||
|
|
||||||
|
fn main() -> Result<(), estring::ParseError> {
|
||||||
|
let res = EString::from("10+5*2+3")
|
||||||
|
.parse::<PlusVec<MulVec<f32>>>()?
|
||||||
|
.iter()
|
||||||
|
.map(|m| m.iter().product::<f32>())
|
||||||
|
.sum::<f32>();
|
||||||
|
|
||||||
|
assert_eq!(res, 23.0);
|
||||||
|
Ok(())
|
||||||
|
}
|
Reference in a new issue