From 83451a90282165e7b3a80cc88162a1f08465c9bb Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 28 Mar 2019 08:38:51 +0100 Subject: [PATCH] Use as_number in quickstart example Otherwise the example would not allow mixed float and int arguments. --- README.md | 6 +++--- src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ff438d1..51fdacc 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Add `evalexpr` as dependency to your `Cargo.toml`: ```toml [dependencies] -evalexpr = "1" +evalexpr = "2" ``` Add the `extern crate` definition to your `main.rs` or `lib.rs`: @@ -67,7 +67,7 @@ context.set_function("avg", Function::new(Some(2) /* argument amount */, Box::ne if let (Value::Int(a), Value::Int(b)) = (&arguments[0], &arguments[1]) { Ok(Value::Int((a + b) / 2)) } else { - Ok(Value::Float((arguments[0].as_float()? + arguments[1].as_float()?) / 2.0)) + Ok(Value::Float((arguments[0].as_number()? + arguments[1].as_number()?) / 2.0)) } }))).unwrap(); // Do proper error handling here @@ -251,7 +251,7 @@ This can be done like this in the `Cargo.toml`: ```toml [dependencies] -evalexpr = {version = "1", features = ["serde"]} +evalexpr = {version = "2", features = ["serde"]} ``` This crate implements `serde::de::Deserialize` for its type `Node` that represents a parsed expression tree. diff --git a/src/lib.rs b/src/lib.rs index 061c375..6e65fde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,7 +54,7 @@ //! if let (Value::Int(a), Value::Int(b)) = (&arguments[0], &arguments[1]) { //! Ok(Value::Int((a + b) / 2)) //! } else { -//! Ok(Value::Float((arguments[0].as_float()? + arguments[1].as_float()?) / 2.0)) +//! Ok(Value::Float((arguments[0].as_number()? + arguments[1].as_number()?) / 2.0)) //! } //! }))).unwrap(); // Do proper error handling here //!