Merge pull request #54 from Atul9/rust-2018

Update crate for Rust 2018
This commit is contained in:
ISibboI 2019-06-14 19:10:59 +02:00 committed by GitHub
commit 962a99e5c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 85 additions and 84 deletions

View File

@ -10,6 +10,7 @@ homepage = "https://github.com/ISibboI/evalexpr"
documentation = "https://docs.rs/evalexpr" documentation = "https://docs.rs/evalexpr"
readme = "README.md" readme = "README.md"
license = "MIT" license = "MIT"
edition = "2018"
[lib] [lib]
name = "evalexpr" name = "evalexpr"

View File

@ -1,9 +1,9 @@
use std::collections::HashMap; use std::collections::HashMap;
use function::Function; use crate::function::Function;
use value::value_type::ValueType; use crate::value::value_type::ValueType;
use EvalexprError; use crate::EvalexprError;
use EvalexprResult; use crate::EvalexprResult;
use crate::value::Value; use crate::value::Value;

View File

@ -1,10 +1,10 @@
use std::fmt; use std::fmt;
use EvalexprError; use crate::EvalexprError;
impl fmt::Display for EvalexprError { impl fmt::Display for EvalexprError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use EvalexprError::*; use crate::EvalexprError::*;
match self { match self {
WrongOperatorArgumentAmount { expected, actual } => write!( WrongOperatorArgumentAmount { expected, actual } => write!(
f, f,

View File

@ -5,8 +5,8 @@
//! The module also contains some helper functions starting with `expect_` that check for a condition and return `Err(_)` if the condition is not fulfilled. //! The module also contains some helper functions starting with `expect_` that check for a condition and return `Err(_)` if the condition is not fulfilled.
//! They are meant as shortcuts to not write the same error checking code everywhere. //! They are meant as shortcuts to not write the same error checking code everywhere.
use token::PartialToken; use crate::token::PartialToken;
use value::{value_type::ValueType, TupleType}; use crate::value::{value_type::ValueType, TupleType};
use crate::value::Value; use crate::value::Value;

View File

@ -2,10 +2,10 @@
use regex::Regex; use regex::Regex;
use crate::error::*; use crate::error::*;
use value::{FloatType, IntType}; use crate::value::{FloatType, IntType};
use EvalexprError; use crate::EvalexprError;
use Function; use crate::Function;
use Value; use crate::Value;
pub fn builtin_function(identifier: &str) -> Option<Function> { pub fn builtin_function(identifier: &str) -> Option<Function> {
match identifier { match identifier {

View File

@ -1,7 +1,7 @@
use std::fmt; use std::fmt;
use error::EvalexprResult; use crate::error::EvalexprResult;
use value::Value; use crate::value::Value;
pub(crate) mod builtin; pub(crate) mod builtin;
@ -20,14 +20,14 @@ pub(crate) mod builtin;
/// assert_eq!(eval_with_context("id(4)", &context), Ok(Value::from(4))); /// assert_eq!(eval_with_context("id(4)", &context), Ok(Value::from(4)));
/// ``` /// ```
pub struct Function { pub struct Function {
function: Box<Fn(&Value) -> EvalexprResult<Value>>, function: Box<dyn Fn(&Value) -> EvalexprResult<Value>>,
} }
impl Function { impl Function {
/// Creates a user-defined function. /// Creates a user-defined function.
/// ///
/// The `function` is a boxed function that takes a `Value` and returns a `EvalexprResult<Value, Error>`. /// The `function` is a boxed function that takes a `Value` and returns a `EvalexprResult<Value, Error>`.
pub fn new(function: Box<Fn(&Value) -> EvalexprResult<Value>>) -> Self { pub fn new(function: Box<dyn Fn(&Value) -> EvalexprResult<Value>>) -> Self {
Self { function } Self { function }
} }

View File

@ -1,16 +1,16 @@
use token; use crate::token;
use tree; use crate::tree;
use value::TupleType; use crate::value::TupleType;
use Context; use crate::Context;
use EmptyContext; use crate::EmptyContext;
use EmptyType; use crate::EmptyType;
use EvalexprError; use crate::EvalexprError;
use EvalexprResult; use crate::EvalexprResult;
use FloatType; use crate::FloatType;
use IntType; use crate::IntType;
use Node; use crate::Node;
use Value; use crate::Value;
use EMPTY_VALUE; use crate::EMPTY_VALUE;
/// Evaluate the given expression string. /// Evaluate the given expression string.
/// ///
@ -42,7 +42,7 @@ pub fn eval(string: &str) -> EvalexprResult<Value> {
/// ``` /// ```
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_with_context(string: &str, context: &Context) -> EvalexprResult<Value> { pub fn eval_with_context(string: &str, context: &dyn Context) -> EvalexprResult<Value> {
tree::tokens_to_operator_tree(token::tokenize(string)?)?.eval_with_context(context) tree::tokens_to_operator_tree(token::tokenize(string)?)?.eval_with_context(context)
} }
@ -61,7 +61,7 @@ pub fn eval_with_context(string: &str, context: &Context) -> EvalexprResult<Valu
/// ``` /// ```
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_with_context_mut(string: &str, context: &mut Context) -> EvalexprResult<Value> { pub fn eval_with_context_mut(string: &str, context: &mut dyn Context) -> EvalexprResult<Value> {
tree::tokens_to_operator_tree(token::tokenize(string)?)?.eval_with_context_mut(context) tree::tokens_to_operator_tree(token::tokenize(string)?)?.eval_with_context_mut(context)
} }
@ -146,7 +146,7 @@ pub fn eval_empty(string: &str) -> EvalexprResult<EmptyType> {
/// Evaluate the given expression string into a string with the given context. /// Evaluate the given expression string into a string with the given context.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_string_with_context(string: &str, context: &Context) -> EvalexprResult<String> { pub fn eval_string_with_context(string: &str, context: &dyn Context) -> EvalexprResult<String> {
match eval_with_context(string, context) { match eval_with_context(string, context) {
Ok(Value::String(string)) => Ok(string), Ok(Value::String(string)) => Ok(string),
Ok(value) => Err(EvalexprError::expected_string(value)), Ok(value) => Err(EvalexprError::expected_string(value)),
@ -157,7 +157,7 @@ pub fn eval_string_with_context(string: &str, context: &Context) -> EvalexprResu
/// Evaluate the given expression string into an integer with the given context. /// Evaluate the given expression string into an integer with the given context.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_int_with_context(string: &str, context: &Context) -> EvalexprResult<IntType> { pub fn eval_int_with_context(string: &str, context: &dyn Context) -> EvalexprResult<IntType> {
match eval_with_context(string, context) { match eval_with_context(string, context) {
Ok(Value::Int(int)) => Ok(int), Ok(Value::Int(int)) => Ok(int),
Ok(value) => Err(EvalexprError::expected_int(value)), Ok(value) => Err(EvalexprError::expected_int(value)),
@ -168,7 +168,7 @@ pub fn eval_int_with_context(string: &str, context: &Context) -> EvalexprResult<
/// Evaluate the given expression string into a float with the given context. /// Evaluate the given expression string into a float with the given context.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_float_with_context(string: &str, context: &Context) -> EvalexprResult<FloatType> { pub fn eval_float_with_context(string: &str, context: &dyn Context) -> EvalexprResult<FloatType> {
match eval_with_context(string, context) { match eval_with_context(string, context) {
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
Ok(value) => Err(EvalexprError::expected_float(value)), Ok(value) => Err(EvalexprError::expected_float(value)),
@ -180,7 +180,7 @@ pub fn eval_float_with_context(string: &str, context: &Context) -> EvalexprResul
/// If the result of the expression is an integer, it is silently converted into a float. /// If the result of the expression is an integer, it is silently converted into a float.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_number_with_context(string: &str, context: &Context) -> EvalexprResult<FloatType> { pub fn eval_number_with_context(string: &str, context: &dyn Context) -> EvalexprResult<FloatType> {
match eval_with_context(string, context) { match eval_with_context(string, context) {
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
Ok(Value::Int(int)) => Ok(int as FloatType), Ok(Value::Int(int)) => Ok(int as FloatType),
@ -192,7 +192,7 @@ pub fn eval_number_with_context(string: &str, context: &Context) -> EvalexprResu
/// Evaluate the given expression string into a boolean with the given context. /// Evaluate the given expression string into a boolean with the given context.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_boolean_with_context(string: &str, context: &Context) -> EvalexprResult<bool> { pub fn eval_boolean_with_context(string: &str, context: &dyn Context) -> EvalexprResult<bool> {
match eval_with_context(string, context) { match eval_with_context(string, context) {
Ok(Value::Boolean(boolean)) => Ok(boolean), Ok(Value::Boolean(boolean)) => Ok(boolean),
Ok(value) => Err(EvalexprError::expected_boolean(value)), Ok(value) => Err(EvalexprError::expected_boolean(value)),
@ -203,7 +203,7 @@ pub fn eval_boolean_with_context(string: &str, context: &Context) -> EvalexprRes
/// Evaluate the given expression string into a tuple with the given context. /// Evaluate the given expression string into a tuple with the given context.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_tuple_with_context(string: &str, context: &Context) -> EvalexprResult<TupleType> { pub fn eval_tuple_with_context(string: &str, context: &dyn Context) -> EvalexprResult<TupleType> {
match eval_with_context(string, context) { match eval_with_context(string, context) {
Ok(Value::Tuple(tuple)) => Ok(tuple), Ok(Value::Tuple(tuple)) => Ok(tuple),
Ok(value) => Err(EvalexprError::expected_tuple(value)), Ok(value) => Err(EvalexprError::expected_tuple(value)),
@ -214,7 +214,7 @@ pub fn eval_tuple_with_context(string: &str, context: &Context) -> EvalexprResul
/// Evaluate the given expression string into an empty value with the given context. /// Evaluate the given expression string into an empty value with the given context.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_empty_with_context(string: &str, context: &Context) -> EvalexprResult<EmptyType> { pub fn eval_empty_with_context(string: &str, context: &dyn Context) -> EvalexprResult<EmptyType> {
match eval_with_context(string, context) { match eval_with_context(string, context) {
Ok(Value::Empty) => Ok(EMPTY_VALUE), Ok(Value::Empty) => Ok(EMPTY_VALUE),
Ok(value) => Err(EvalexprError::expected_empty(value)), Ok(value) => Err(EvalexprError::expected_empty(value)),
@ -225,7 +225,7 @@ pub fn eval_empty_with_context(string: &str, context: &Context) -> EvalexprResul
/// Evaluate the given expression string into a string with the given mutable context. /// Evaluate the given expression string into a string with the given mutable context.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_string_with_context_mut(string: &str, context: &mut Context) -> EvalexprResult<String> { pub fn eval_string_with_context_mut(string: &str, context: &mut dyn Context) -> EvalexprResult<String> {
match eval_with_context_mut(string, context) { match eval_with_context_mut(string, context) {
Ok(Value::String(string)) => Ok(string), Ok(Value::String(string)) => Ok(string),
Ok(value) => Err(EvalexprError::expected_string(value)), Ok(value) => Err(EvalexprError::expected_string(value)),
@ -236,7 +236,7 @@ pub fn eval_string_with_context_mut(string: &str, context: &mut Context) -> Eval
/// Evaluate the given expression string into an integer with the given mutable context. /// Evaluate the given expression string into an integer with the given mutable context.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_int_with_context_mut(string: &str, context: &mut Context) -> EvalexprResult<IntType> { pub fn eval_int_with_context_mut(string: &str, context: &mut dyn Context) -> EvalexprResult<IntType> {
match eval_with_context_mut(string, context) { match eval_with_context_mut(string, context) {
Ok(Value::Int(int)) => Ok(int), Ok(Value::Int(int)) => Ok(int),
Ok(value) => Err(EvalexprError::expected_int(value)), Ok(value) => Err(EvalexprError::expected_int(value)),
@ -249,7 +249,7 @@ pub fn eval_int_with_context_mut(string: &str, context: &mut Context) -> Evalexp
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_float_with_context_mut( pub fn eval_float_with_context_mut(
string: &str, string: &str,
context: &mut Context, context: &mut dyn Context,
) -> EvalexprResult<FloatType> { ) -> EvalexprResult<FloatType> {
match eval_with_context_mut(string, context) { match eval_with_context_mut(string, context) {
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
@ -264,7 +264,7 @@ pub fn eval_float_with_context_mut(
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_number_with_context_mut( pub fn eval_number_with_context_mut(
string: &str, string: &str,
context: &mut Context, context: &mut dyn Context,
) -> EvalexprResult<FloatType> { ) -> EvalexprResult<FloatType> {
match eval_with_context_mut(string, context) { match eval_with_context_mut(string, context) {
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
@ -277,7 +277,7 @@ pub fn eval_number_with_context_mut(
/// Evaluate the given expression string into a boolean with the given mutable context. /// Evaluate the given expression string into a boolean with the given mutable context.
/// ///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_boolean_with_context_mut(string: &str, context: &mut Context) -> EvalexprResult<bool> { pub fn eval_boolean_with_context_mut(string: &str, context: &mut dyn Context) -> EvalexprResult<bool> {
match eval_with_context_mut(string, context) { match eval_with_context_mut(string, context) {
Ok(Value::Boolean(boolean)) => Ok(boolean), Ok(Value::Boolean(boolean)) => Ok(boolean),
Ok(value) => Err(EvalexprError::expected_boolean(value)), Ok(value) => Err(EvalexprError::expected_boolean(value)),
@ -290,7 +290,7 @@ pub fn eval_boolean_with_context_mut(string: &str, context: &mut Context) -> Eva
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_tuple_with_context_mut( pub fn eval_tuple_with_context_mut(
string: &str, string: &str,
context: &mut Context, context: &mut dyn Context,
) -> EvalexprResult<TupleType> { ) -> EvalexprResult<TupleType> {
match eval_with_context_mut(string, context) { match eval_with_context_mut(string, context) {
Ok(Value::Tuple(tuple)) => Ok(tuple), Ok(Value::Tuple(tuple)) => Ok(tuple),
@ -304,7 +304,7 @@ pub fn eval_tuple_with_context_mut(
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.* /// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
pub fn eval_empty_with_context_mut( pub fn eval_empty_with_context_mut(
string: &str, string: &str,
context: &mut Context, context: &mut dyn Context,
) -> EvalexprResult<EmptyType> { ) -> EvalexprResult<EmptyType> {
match eval_with_context_mut(string, context) { match eval_with_context_mut(string, context) {
Ok(Value::Empty) => Ok(EMPTY_VALUE), Ok(Value::Empty) => Ok(EMPTY_VALUE),

View File

@ -372,12 +372,12 @@ extern crate serde;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
pub use context::{Context, EmptyContext, HashMapContext}; pub use crate::context::{Context, EmptyContext, HashMapContext};
pub use error::{EvalexprError, EvalexprResult}; pub use crate::error::{EvalexprError, EvalexprResult};
pub use function::Function; pub use crate::function::Function;
pub use interface::*; pub use crate::interface::*;
pub use tree::Node; pub use crate::tree::Node;
pub use value::{ pub use crate::value::{
value_type::ValueType, EmptyType, FloatType, IntType, TupleType, Value, EMPTY_VALUE, value_type::ValueType, EmptyType, FloatType, IntType, TupleType, Value, EMPTY_VALUE,
}; };

View File

@ -1,6 +1,6 @@
use std::fmt::{Display, Error, Formatter}; use std::fmt::{Display, Error, Formatter};
use operator::*; use crate::operator::*;
impl Display for Operator { impl Display for Operator {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {

View File

@ -1,4 +1,4 @@
use function::builtin::builtin_function; use crate::function::builtin::builtin_function;
use crate::{context::Context, error::*, value::Value}; use crate::{context::Context, error::*, value::Value};

View File

@ -1,6 +1,6 @@
use std::fmt; use std::fmt;
use token::{PartialToken, Token}; use crate::token::{PartialToken, Token};
impl fmt::Display for Token { impl fmt::Display for Token {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {

View File

@ -1,5 +1,5 @@
use error::{EvalexprError, EvalexprResult}; use crate::error::{EvalexprError, EvalexprResult};
use value::{FloatType, IntType}; use crate::value::{FloatType, IntType};
mod display; mod display;

View File

@ -1,5 +1,5 @@
use std::fmt::{Display, Error, Formatter}; use std::fmt::{Display, Error, Formatter};
use Node; use crate::Node;
impl Display for Node { impl Display for Node {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {

View File

@ -1,5 +1,5 @@
use std::slice::Iter; use std::slice::Iter;
use Node; use crate::Node;
/// An iterator that traverses an operator tree in pre-order. /// An iterator that traverses an operator tree in pre-order.
pub struct NodeIter<'a> { pub struct NodeIter<'a> {

View File

@ -1,9 +1,9 @@
use token::Token; use crate::token::Token;
use value::{TupleType, EMPTY_VALUE}; use crate::value::{TupleType, EMPTY_VALUE};
use EmptyContext; use crate::EmptyContext;
use EmptyType; use crate::EmptyType;
use FloatType; use crate::FloatType;
use IntType; use crate::IntType;
use crate::{ use crate::{
context::Context, context::Context,
@ -120,7 +120,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node with the given context. /// Evaluates the operator tree rooted at this node with the given context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_with_context(&self, context: &Context) -> EvalexprResult<Value> { pub fn eval_with_context(&self, context: &dyn Context) -> EvalexprResult<Value> {
let mut arguments = Vec::new(); let mut arguments = Vec::new();
for child in self.children() { for child in self.children() {
arguments.push(child.eval_with_context(context)?); arguments.push(child.eval_with_context(context)?);
@ -131,7 +131,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node with the given mutable context. /// Evaluates the operator tree rooted at this node with the given mutable context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_with_context_mut(&self, context: &mut Context) -> EvalexprResult<Value> { pub fn eval_with_context_mut(&self, context: &mut dyn Context) -> EvalexprResult<Value> {
let mut arguments = Vec::new(); let mut arguments = Vec::new();
for child in self.children() { for child in self.children() {
arguments.push(child.eval_with_context_mut(context)?); arguments.push(child.eval_with_context_mut(context)?);
@ -149,7 +149,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into a string with an the given context. /// Evaluates the operator tree rooted at this node into a string with an the given context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_string_with_context(&self, context: &Context) -> EvalexprResult<String> { pub fn eval_string_with_context(&self, context: &dyn Context) -> EvalexprResult<String> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::String(string)) => Ok(string), Ok(Value::String(string)) => Ok(string),
Ok(value) => Err(EvalexprError::expected_string(value)), Ok(value) => Err(EvalexprError::expected_string(value)),
@ -160,7 +160,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into a float with an the given context. /// Evaluates the operator tree rooted at this node into a float with an the given context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_float_with_context(&self, context: &Context) -> EvalexprResult<FloatType> { pub fn eval_float_with_context(&self, context: &dyn Context) -> EvalexprResult<FloatType> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
Ok(value) => Err(EvalexprError::expected_float(value)), Ok(value) => Err(EvalexprError::expected_float(value)),
@ -171,7 +171,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into an integer with an the given context. /// Evaluates the operator tree rooted at this node into an integer with an the given context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_int_with_context(&self, context: &Context) -> EvalexprResult<IntType> { pub fn eval_int_with_context(&self, context: &dyn Context) -> EvalexprResult<IntType> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Int(int)) => Ok(int), Ok(Value::Int(int)) => Ok(int),
Ok(value) => Err(EvalexprError::expected_int(value)), Ok(value) => Err(EvalexprError::expected_int(value)),
@ -183,7 +183,7 @@ impl Node {
/// If the result of the expression is an integer, it is silently converted into a float. /// If the result of the expression is an integer, it is silently converted into a float.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_number_with_context(&self, context: &Context) -> EvalexprResult<FloatType> { pub fn eval_number_with_context(&self, context: &dyn Context) -> EvalexprResult<FloatType> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Int(int)) => Ok(int as FloatType), Ok(Value::Int(int)) => Ok(int as FloatType),
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
@ -195,7 +195,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into a boolean with an the given context. /// Evaluates the operator tree rooted at this node into a boolean with an the given context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_boolean_with_context(&self, context: &Context) -> EvalexprResult<bool> { pub fn eval_boolean_with_context(&self, context: &dyn Context) -> EvalexprResult<bool> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Boolean(boolean)) => Ok(boolean), Ok(Value::Boolean(boolean)) => Ok(boolean),
Ok(value) => Err(EvalexprError::expected_boolean(value)), Ok(value) => Err(EvalexprError::expected_boolean(value)),
@ -206,7 +206,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into a tuple with an the given context. /// Evaluates the operator tree rooted at this node into a tuple with an the given context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_tuple_with_context(&self, context: &Context) -> EvalexprResult<TupleType> { pub fn eval_tuple_with_context(&self, context: &dyn Context) -> EvalexprResult<TupleType> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Tuple(tuple)) => Ok(tuple), Ok(Value::Tuple(tuple)) => Ok(tuple),
Ok(value) => Err(EvalexprError::expected_tuple(value)), Ok(value) => Err(EvalexprError::expected_tuple(value)),
@ -217,7 +217,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into an empty value with an the given context. /// Evaluates the operator tree rooted at this node into an empty value with an the given context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_empty_with_context(&self, context: &Context) -> EvalexprResult<EmptyType> { pub fn eval_empty_with_context(&self, context: &dyn Context) -> EvalexprResult<EmptyType> {
match self.eval_with_context(context) { match self.eval_with_context(context) {
Ok(Value::Empty) => Ok(EMPTY_VALUE), Ok(Value::Empty) => Ok(EMPTY_VALUE),
Ok(value) => Err(EvalexprError::expected_empty(value)), Ok(value) => Err(EvalexprError::expected_empty(value)),
@ -228,7 +228,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into a string with an the given mutable context. /// Evaluates the operator tree rooted at this node into a string with an the given mutable context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_string_with_context_mut(&self, context: &mut Context) -> EvalexprResult<String> { pub fn eval_string_with_context_mut(&self, context: &mut dyn Context) -> EvalexprResult<String> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::String(string)) => Ok(string), Ok(Value::String(string)) => Ok(string),
Ok(value) => Err(EvalexprError::expected_string(value)), Ok(value) => Err(EvalexprError::expected_string(value)),
@ -239,7 +239,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into a float with an the given mutable context. /// Evaluates the operator tree rooted at this node into a float with an the given mutable context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_float_with_context_mut(&self, context: &mut Context) -> EvalexprResult<FloatType> { pub fn eval_float_with_context_mut(&self, context: &mut dyn Context) -> EvalexprResult<FloatType> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
Ok(value) => Err(EvalexprError::expected_float(value)), Ok(value) => Err(EvalexprError::expected_float(value)),
@ -250,7 +250,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into an integer with an the given mutable context. /// Evaluates the operator tree rooted at this node into an integer with an the given mutable context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_int_with_context_mut(&self, context: &mut Context) -> EvalexprResult<IntType> { pub fn eval_int_with_context_mut(&self, context: &mut dyn Context) -> EvalexprResult<IntType> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Int(int)) => Ok(int), Ok(Value::Int(int)) => Ok(int),
Ok(value) => Err(EvalexprError::expected_int(value)), Ok(value) => Err(EvalexprError::expected_int(value)),
@ -262,7 +262,7 @@ impl Node {
/// If the result of the expression is an integer, it is silently converted into a float. /// If the result of the expression is an integer, it is silently converted into a float.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_number_with_context_mut(&self, context: &mut Context) -> EvalexprResult<FloatType> { pub fn eval_number_with_context_mut(&self, context: &mut dyn Context) -> EvalexprResult<FloatType> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Int(int)) => Ok(int as FloatType), Ok(Value::Int(int)) => Ok(int as FloatType),
Ok(Value::Float(float)) => Ok(float), Ok(Value::Float(float)) => Ok(float),
@ -274,7 +274,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into a boolean with an the given mutable context. /// Evaluates the operator tree rooted at this node into a boolean with an the given mutable context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_boolean_with_context_mut(&self, context: &mut Context) -> EvalexprResult<bool> { pub fn eval_boolean_with_context_mut(&self, context: &mut dyn Context) -> EvalexprResult<bool> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Boolean(boolean)) => Ok(boolean), Ok(Value::Boolean(boolean)) => Ok(boolean),
Ok(value) => Err(EvalexprError::expected_boolean(value)), Ok(value) => Err(EvalexprError::expected_boolean(value)),
@ -285,7 +285,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into a tuple with an the given mutable context. /// Evaluates the operator tree rooted at this node into a tuple with an the given mutable context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_tuple_with_context_mut(&self, context: &mut Context) -> EvalexprResult<TupleType> { pub fn eval_tuple_with_context_mut(&self, context: &mut dyn Context) -> EvalexprResult<TupleType> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Tuple(tuple)) => Ok(tuple), Ok(Value::Tuple(tuple)) => Ok(tuple),
Ok(value) => Err(EvalexprError::expected_tuple(value)), Ok(value) => Err(EvalexprError::expected_tuple(value)),
@ -296,7 +296,7 @@ impl Node {
/// Evaluates the operator tree rooted at this node into an empty value with an the given mutable context. /// Evaluates the operator tree rooted at this node into an empty value with an the given mutable context.
/// ///
/// Fails, if one of the operators in the expression tree fails. /// Fails, if one of the operators in the expression tree fails.
pub fn eval_empty_with_context_mut(&self, context: &mut Context) -> EvalexprResult<EmptyType> { pub fn eval_empty_with_context_mut(&self, context: &mut dyn Context) -> EvalexprResult<EmptyType> {
match self.eval_with_context_mut(context) { match self.eval_with_context_mut(context) {
Ok(Value::Empty) => Ok(EMPTY_VALUE), Ok(Value::Empty) => Ok(EMPTY_VALUE),
Ok(value) => Err(EvalexprError::expected_empty(value)), Ok(value) => Err(EvalexprError::expected_empty(value)),

View File

@ -1,6 +1,6 @@
use std::fmt::{Display, Error, Formatter}; use std::fmt::{Display, Error, Formatter};
use Value; use crate::Value;
impl Display for Value { impl Display for Value {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {

View File

@ -1,4 +1,4 @@
use error::{EvalexprError, EvalexprResult}; use crate::error::{EvalexprError, EvalexprResult};
mod display; mod display;
pub mod value_type; pub mod value_type;
@ -202,7 +202,7 @@ impl From<()> for Value {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use value::{TupleType, Value}; use crate::value::{TupleType, Value};
#[test] #[test]
fn test_value_conversions() { fn test_value_conversions() {

View File

@ -1,4 +1,4 @@
use Value; use crate::Value;
/// The type of a `Value`. /// The type of a `Value`.
#[derive(Clone, Copy, Eq, PartialEq)] #[derive(Clone, Copy, Eq, PartialEq)]