diff --git a/libimagentryfilter/src/builtin/content/mod.rs b/libimagentryfilter/src/builtin/content/mod.rs new file mode 100644 index 00000000..e69de29b diff --git a/libimagentryfilter/src/builtin/header/field_eq.rs b/libimagentryfilter/src/builtin/header/field_eq.rs new file mode 100644 index 00000000..fc4e1e77 --- /dev/null +++ b/libimagentryfilter/src/builtin/header/field_eq.rs @@ -0,0 +1,36 @@ +use libimagstore::store::Entry; + +use builtin::header::field_path::FieldPath; +use filter::Filter; + +use toml::Value; + +/// Check whether certain header field in a entry is equal to a value +pub struct FieldEq { + header_field_path: FieldPath, + expected_value: Value +} + +impl FieldEq { + + pub fn new(path: FieldPath, expected_value: Value) -> FieldEq { + FieldEq { + header_field_path: path, + expected_value: expected_value, + } + } + +} + +impl Filter for FieldEq { + + fn filter(&self, e: &Entry) -> bool { + let header = e.get_header(); + self.header_field_path + .walk(header) + .map(|v| self.expected_value == v.clone()) + .unwrap_or(false) + } + +} + diff --git a/libimagentryfilter/src/builtin/header/field_path/element.rs b/libimagentryfilter/src/builtin/header/field_path/element.rs new file mode 100644 index 00000000..044289aa --- /dev/null +++ b/libimagentryfilter/src/builtin/header/field_path/element.rs @@ -0,0 +1,18 @@ +use std::fmt::{Display, Formatter}; +use std::fmt::Error as FmtError; + +#[derive(Debug)] +pub struct FieldPathElement { + name: String +} + +impl Display for FieldPathElement { + + fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { + try!(write!(fmt, "{}", self.name)); + Ok(()) + } + +} + + diff --git a/libimagentryfilter/src/builtin/header/field_path/error.rs b/libimagentryfilter/src/builtin/header/field_path/error.rs new file mode 100644 index 00000000..69703cbf --- /dev/null +++ b/libimagentryfilter/src/builtin/header/field_path/error.rs @@ -0,0 +1,39 @@ +use std::fmt::{Display, Formatter}; +use std::fmt::Error as FmtError; +use std::error::Error; + +use builtin::header::field_path::element::FieldPathElement; + +#[derive(Debug)] +pub struct FieldPathParsingError { + source: String, + token: FieldPathElement +} + +impl FieldPathParsingError { + + pub fn new(source: String, token: FieldPathElement) -> FieldPathParsingError { + FieldPathParsingError { source: source, token: token } + } +} + +impl Display for FieldPathParsingError { + + fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { + try!(write!(fmt, "Failed to compile '{}', failed at: '{}'", self.source, self.token)); + Ok(()) + } + +} + +impl Error for FieldPathParsingError { + + fn description(&self) -> &str { + &self.source[..] + } + + fn cause(&self) -> Option<&Error> { + None + } + +} diff --git a/libimagentryfilter/src/builtin/header/field_path/mod.rs b/libimagentryfilter/src/builtin/header/field_path/mod.rs new file mode 100644 index 00000000..0a8e61df --- /dev/null +++ b/libimagentryfilter/src/builtin/header/field_path/mod.rs @@ -0,0 +1,35 @@ +use std::fmt::{Display, Formatter}; +use std::fmt::Error as FmtError; +use std::error::Error; + +use toml::Value; + +pub mod element; +pub mod error; + +use libimagstore::store::Entry; +use libimagstore::store::EntryHeader; + +use builtin::header::field_path::element::FieldPathElement; +use builtin::header::field_path::error::FieldPathParsingError; + +pub struct FieldPath { + elements: Vec, +} + +impl FieldPath { + + pub fn new(elements: Vec) -> FieldPath { + unimplemented!() + } + + pub fn compile(source: String) -> Result { + unimplemented!() + } + + pub fn walk(&self, e: &EntryHeader) -> Option { + unimplemented!() + } + +} + diff --git a/libimagentryfilter/src/builtin/header/mod.rs b/libimagentryfilter/src/builtin/header/mod.rs new file mode 100644 index 00000000..14b98d62 --- /dev/null +++ b/libimagentryfilter/src/builtin/header/mod.rs @@ -0,0 +1,3 @@ +pub mod field_eq; +pub mod field_path; + diff --git a/libimagentryfilter/src/builtin/mod.rs b/libimagentryfilter/src/builtin/mod.rs index e69de29b..260f1a1b 100644 --- a/libimagentryfilter/src/builtin/mod.rs +++ b/libimagentryfilter/src/builtin/mod.rs @@ -0,0 +1,2 @@ +pub mod content; +pub mod header;