Initialize structure for header builtins

This commit is contained in:
Matthias Beyer 2016-02-02 15:27:17 +01:00
parent 0fb331f25a
commit 012ca4a427
7 changed files with 133 additions and 0 deletions

View 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)
}
}

View 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(())
}
}

View 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
}
}

View 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!()
}
}

View file

@ -0,0 +1,3 @@
pub mod field_eq;
pub mod field_path;

View file

@ -0,0 +1,2 @@
pub mod content;
pub mod header;