update serde to version 0.9, bump version 0.4.0

This commit is contained in:
fengcen 2017-02-13 08:20:53 +08:00
parent 1c4d522007
commit ce671d0f0a
8 changed files with 52 additions and 45 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "eval" name = "eval"
version = "0.3.2" version = "0.4.0"
description = "Expression evaluator" description = "Expression evaluator"
keywords = ["expression", "evaluate", "evaluator", "expr", "template"] keywords = ["expression", "evaluate", "evaluator", "expr", "template"]
authors = ["fengcen <fengcen.love@gmail.com>"] authors = ["fengcen <fengcen.love@gmail.com>"]
@ -15,8 +15,8 @@ name = "eval"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
serde = "^0.8" serde = "^0.9"
serde_json = "^0.8" serde_json = "^0.9"
quick-error = "^1.1" quick-error = "^1.1"
[features] [features]

View File

@ -2,7 +2,7 @@
eval eval
==== ====
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![docs](https://docs.rs/eval/badge.svg?version=0.3.2 "docs")](https://docs.rs/eval) [![docs](https://docs.rs/eval/badge.svg?version=0.4.0 "docs")](https://docs.rs/eval)
Eval is a powerful expression evaluator. Eval is a powerful expression evaluator.
@ -23,7 +23,7 @@ Add dependency to Cargo.toml
```toml ```toml
[dependencies] [dependencies]
eval = "^0.3" eval = "^0.4"
``` ```
In your `main.rs` or `lib.rs`: In your `main.rs` or `lib.rs`:

View File

@ -82,14 +82,12 @@ fn create_is_empty_fuction() -> Function {
Function { Function {
max_args: Some(1), max_args: Some(1),
min_args: Some(1), min_args: Some(1),
compiled: Box::new(|values| { compiled: Box::new(|values| match *values.first().unwrap() {
match *values.first().unwrap() {
Value::String(ref string) => Ok(to_value(string.is_empty())), Value::String(ref string) => Ok(to_value(string.is_empty())),
Value::Array(ref array) => Ok(to_value(array.is_empty())), Value::Array(ref array) => Ok(to_value(array.is_empty())),
Value::Object(ref object) => Ok(to_value(object.is_empty())), Value::Object(ref object) => Ok(to_value(object.is_empty())),
Value::Null => Ok(to_value(true)), Value::Null => Ok(to_value(true)),
_ => Ok(to_value(false)), _ => Ok(to_value(false)),
}
}), }),
} }
} }

View File

@ -109,11 +109,19 @@ mod builtin;
mod expr; mod expr;
pub use expr::ExecOptions; pub use expr::ExecOptions;
pub use serde_json::{Value, to_value}; pub use serde_json::Value;
pub use error::Error; pub use error::Error;
pub use function::Function; pub use function::Function;
pub use expr::Expr; pub use expr::Expr;
use std::collections::HashMap; use std::collections::HashMap;
use serde_json::to_value as json_to_value;
use serde::Serialize;
/// Convert variable to `serde_json::Value`
pub fn to_value<S: Serialize>(v: S) -> Value {
json_to_value(v).unwrap()
}
/// Custom context. /// Custom context.
pub type Context = HashMap<String, Value>; pub type Context = HashMap<String, Value>;
@ -134,7 +142,7 @@ type Compiled = Box<Fn(&[Context], &Functions) -> Result<Value, Error>>;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serde_json::to_value; use to_value;
use error::Error; use error::Error;
use Expr; use Expr;
use tree::Tree; use tree::Tree;

View File

@ -1,5 +1,6 @@
use serde_json::{Value, to_value}; use serde_json::Value;
use to_value;
use error::Error; use error::Error;
pub trait Math { pub trait Math {
@ -162,9 +163,7 @@ trait Type {
impl Type for Value { impl Type for Value {
fn get_f64(&self) -> f64 { fn get_f64(&self) -> f64 {
match *self { match *self {
Value::F64(f) => f, Value::Number(ref n) => n.as_f64().unwrap(),
Value::I64(f) => f as f64,
Value::U64(f) => f as f64,
_ => panic!("not a number"), _ => panic!("not a number"),
} }
} }

View File

@ -1,6 +1,7 @@
use std::str::FromStr; use std::str::FromStr;
use serde_json::{Value, to_value}; use serde_json::Value;
use to_value;
use error::Error; use error::Error;
use node::Node; use node::Node;

View File

@ -1,7 +1,8 @@
use std::str::FromStr; use std::str::FromStr;
use std::clone::Clone; use std::clone::Clone;
use serde_json::{Value, to_value}; use serde_json::Value;
use to_value;
use math::Math; use math::Math;
use operator::Operator; use operator::Operator;
use node::Node; use node::Node;
@ -368,7 +369,7 @@ impl Tree {
if child.operator.is_identifier() { if child.operator.is_identifier() {
value = value.as_ref() value = value.as_ref()
.unwrap() .unwrap()
.find(child.operator.get_identifier()) .get(child.operator.get_identifier())
.cloned(); .cloned();
} else { } else {
return Err(Error::ExpectedIdentifier); return Err(Error::ExpectedIdentifier);
@ -405,7 +406,7 @@ impl Tree {
if name.is_string() { if name.is_string() {
value = value.as_ref() value = value.as_ref()
.unwrap() .unwrap()
.find(name.as_str().unwrap()) .get(name.as_str().unwrap())
.cloned(); .cloned();
} else { } else {
return Err(Error::ExpectedIdentifier); return Err(Error::ExpectedIdentifier);