fix markdown syntax.

This commit is contained in:
fengcen 2017-02-25 14:51:55 +08:00
parent ce671d0f0a
commit 1b690b634c

View File

@ -1,24 +1,31 @@
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.4.0 "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.
## [Document](https://docs.rs/eval) [Document](https://docs.rs/eval)
--------------------------------
Features
--------
## Features
Supported operators: `!` `!=` `""` `''` `()` `[]` `,` `>` `<` `>=` `<=` `==` Supported operators: `!` `!=` `""` `''` `()` `[]` `,` `>` `<` `>=` `<=` `==`
`+` `-` `*` `/` `%` `&&` `||` `n..m`. `+` `-` `*` `/` `%` `&&` `||` `n..m`.
Built-in functions: `min()` `max()` `len()` `is_empty()` `array()`. Built-in functions: `min()` `max()` `len()` `is_empty()` `array()`.
## Where can eval be used? Where can eval be used?
-----------------------
* Template engine * Template engine
* ... * ...
## Usage Usage
-----
Add dependency to Cargo.toml Add dependency to Cargo.toml
```toml ```toml
@ -32,11 +39,12 @@ In your `main.rs` or `lib.rs`:
extern crate eval; extern crate eval;
``` ```
## Examples Examples
--------
You can do mathematical calculations with supported operators: You can do mathematical calculations with supported operators:
``` ```rust
use eval::{eval, to_value}; use eval::{eval, to_value};
assert_eq!(eval("1 + 2 + 3"), Ok(to_value(6))); assert_eq!(eval("1 + 2 + 3"), Ok(to_value(6)));
@ -47,7 +55,7 @@ assert_eq!(eval("2 / 2 + 3 / 3"), Ok(to_value(2.0)));
You can eval with context: You can eval with context:
``` ```rust
use eval::{Expr, to_value}; use eval::{Expr, to_value};
assert_eq!(Expr::new("foo == bar") assert_eq!(Expr::new("foo == bar")
@ -57,10 +65,9 @@ assert_eq!(Expr::new("foo == bar")
Ok(to_value(true))); Ok(to_value(true)));
``` ```
You can access data like javascript by using `.` and `[]`. `[]` supports expression. You can access data like javascript by using `.` and `[]`. `[]` supports expression.
``` ```rust
use eval::{Expr, to_value}; use eval::{Expr, to_value};
use std::collections::HashMap; use std::collections::HashMap;
@ -73,10 +80,9 @@ assert_eq!(Expr::new("object.foos[1-1] == 'Hello'")
Ok(to_value(true))); Ok(to_value(true)));
``` ```
You can eval with function: You can eval with function:
``` ```rust
use eval::{Expr, to_value}; use eval::{Expr, to_value};
assert_eq!(Expr::new("say_hello()") assert_eq!(Expr::new("say_hello()")
@ -85,24 +91,24 @@ assert_eq!(Expr::new("say_hello()")
Ok(to_value("Hello world!"))); Ok(to_value("Hello world!")));
``` ```
You can create an array with `array()`: You can create an array with `array()`:
``` ```rust
use eval::{eval, to_value}; use eval::{eval, to_value};
assert_eq!(eval("array(1, 2, 3, 4, 5)"), Ok(to_value(vec![1, 2, 3, 4, 5]))); assert_eq!(eval("array(1, 2, 3, 4, 5)"), Ok(to_value(vec![1, 2, 3, 4, 5])));
``` ```
You can create an integer array with `n..m`: You can create an integer array with `n..m`:
``` ```rust
use eval::{eval, to_value}; use eval::{eval, to_value};
assert_eq!(eval("0..5"), Ok(to_value(vec![0, 1, 2, 3, 4]))); assert_eq!(eval("0..5"), Ok(to_value(vec![0, 1, 2, 3, 4])));
``` ```
## License License
-------
eval is primarily distributed under the terms of the MIT license. eval is primarily distributed under the terms of the MIT license.
See [LICENSE](LICENSE) for details. See [LICENSE](LICENSE) for details.