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

View File

@ -2,7 +2,7 @@
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)
[![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.
@ -23,7 +23,7 @@ Add dependency to Cargo.toml
```toml
[dependencies]
eval = "^0.3"
eval = "^0.4"
```
In your `main.rs` or `lib.rs`:

View File

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

View File

@ -109,11 +109,19 @@ mod builtin;
mod expr;
pub use expr::ExecOptions;
pub use serde_json::{Value, to_value};
pub use serde_json::Value;
pub use error::Error;
pub use function::Function;
pub use expr::Expr;
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.
pub type Context = HashMap<String, Value>;
@ -134,7 +142,7 @@ type Compiled = Box<Fn(&[Context], &Functions) -> Result<Value, Error>>;
#[cfg(test)]
mod tests {
use serde_json::to_value;
use to_value;
use error::Error;
use Expr;
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;
pub trait Math {
@ -162,9 +163,7 @@ trait Type {
impl Type for Value {
fn get_f64(&self) -> f64 {
match *self {
Value::F64(f) => f,
Value::I64(f) => f as f64,
Value::U64(f) => f as f64,
Value::Number(ref n) => n.as_f64().unwrap(),
_ => panic!("not a number"),
}
}

View File

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

View File

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