From 650afd50dbe87aa88532ad6cd8dcbb4c51eb5602 Mon Sep 17 00:00:00 2001 From: Anton Shramko Date: Mon, 10 Sep 2018 01:22:48 +0300 Subject: [PATCH 1/2] adding partialeq and serde serialize/deserialize support --- src/expr/mod.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/expr/mod.rs b/src/expr/mod.rs index c79e99e..62e5efb 100644 --- a/src/expr/mod.rs +++ b/src/expr/mod.rs @@ -2,9 +2,14 @@ use {Function, Functions, Context, Contexts, Compiled, Value}; use tree::Tree; use error::Error; -use serde::Serialize; use to_value; -use std::fmt; +use std::{fmt, cmp}; + +use serde::de::{self, Deserialize}; +use serde::ser::Serialize; + +use serde::Deserializer; +use serde::Serializer; /// Expression builder @@ -88,6 +93,31 @@ impl fmt::Debug for Expr { } } +impl cmp::PartialEq for Expr { + fn eq(&self, other: &Expr) -> bool { + self.expression == other.expression + } +} + +impl Serialize for Expr { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(format!("{:?}", self).as_str()) + } +} + +impl<'de> Deserialize<'de> for Expr { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + String::deserialize(deserializer) + .and_then(|expr| Expr::new(expr).compile().map_err(de::Error::custom)) + } +} + /// Execute options pub struct ExecOptions<'a> { From 3449ec5f37dd27d85b5ed1ca47bb33aaafb2677b Mon Sep 17 00:00:00 2001 From: Anton Shramko Date: Mon, 17 Sep 2018 02:46:58 +0300 Subject: [PATCH 2/2] cimpiled as ref to public method --- src/expr/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/expr/mod.rs b/src/expr/mod.rs index 62e5efb..0f0e5c3 100644 --- a/src/expr/mod.rs +++ b/src/expr/mod.rs @@ -66,7 +66,8 @@ impl Expr { } } - fn get_compiled(&self) -> Option<&Compiled> { + /// Get reference to compiled object + pub fn get_compiled(&self) -> Option<&Compiled> { self.compiled.as_ref() } }