Initialize structure for header builtins
This commit is contained in:
parent
0fb331f25a
commit
012ca4a427
7 changed files with 133 additions and 0 deletions
0
libimagentryfilter/src/builtin/content/mod.rs
Normal file
0
libimagentryfilter/src/builtin/content/mod.rs
Normal file
36
libimagentryfilter/src/builtin/header/field_eq.rs
Normal file
36
libimagentryfilter/src/builtin/header/field_eq.rs
Normal file
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
18
libimagentryfilter/src/builtin/header/field_path/element.rs
Normal file
18
libimagentryfilter/src/builtin/header/field_path/element.rs
Normal file
|
@ -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(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
39
libimagentryfilter/src/builtin/header/field_path/error.rs
Normal file
39
libimagentryfilter/src/builtin/header/field_path/error.rs
Normal file
|
@ -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
|
||||
}
|
||||
|
||||
}
|
35
libimagentryfilter/src/builtin/header/field_path/mod.rs
Normal file
35
libimagentryfilter/src/builtin/header/field_path/mod.rs
Normal file
|
@ -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<FieldPathElement>,
|
||||
}
|
||||
|
||||
impl FieldPath {
|
||||
|
||||
pub fn new(elements: Vec<FieldPathElement>) -> FieldPath {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn compile(source: String) -> Result<FieldPath, FieldPathParsingError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn walk(&self, e: &EntryHeader) -> Option<Value> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
}
|
||||
|
3
libimagentryfilter/src/builtin/header/mod.rs
Normal file
3
libimagentryfilter/src/builtin/header/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub mod field_eq;
|
||||
pub mod field_path;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
pub mod content;
|
||||
pub mod header;
|
Loading…
Reference in a new issue