From 5ad335937d29e0cdd8e25a8478aa43222262463c Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Sat, 23 Mar 2019 15:34:05 +0200 Subject: [PATCH] Add lib doc changes to readme Relates to #18 --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 44e54a2..449d7a5 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,31 @@ Functions have a precedence of 190. | `true` | no | Expression is interpreted as `Value::Bool` | | `.34` | no | Expression is interpreted as `Value::Float` | +### [serde](https://serde.rs) + +This crate implements `serde::de::Deserialize` for its type `Node` that represents a parsed expression tree. +The implementation expects a `string` as input. +Example parsing with [ron format](docs.rs/ron): + +```rust +extern crate ron; +use evalexpr::*; + +let mut configuration = HashMapConfiguration::new(); +configuration.insert_variable("five", 5); + +// In ron format, strings are surrounded by " +let serialized_free = "\"five * five\""; +match ron::de::from_str::(serialized_free) { + Ok(free) => assert_eq!(free.eval_with_configuration(&configuration), Ok(Value::from(25))), + Err(error) => { + // Handle error + }, +} +``` + +With `serde`, expressions can be integrated into arbitrarily complex data. + ## License This crate is primarily distributed under the terms of the MIT license.