Skip to content
This repository was archived by the owner on Sep 26, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,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()
}
}
Expand All @@ -88,6 +94,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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(format!("{:?}", self).as_str())
}
}

impl<'de> Deserialize<'de> for Expr {
fn deserialize<D>(deserializer: D) -> Result<Expr, D::Error>
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> {
Expand Down