libimagentryfilter: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
8236e73402
commit
49ec0702fd
11 changed files with 42 additions and 63 deletions
|
@ -26,10 +26,12 @@ log = "0.4.0"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
semver = "0.9"
|
semver = "0.9"
|
||||||
toml = "0.4"
|
toml = "0.4"
|
||||||
toml-query = "0.7"
|
toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "failure" }
|
||||||
error-chain = "0.12"
|
failure = "0.1"
|
||||||
|
failure_derive = "0.1"
|
||||||
|
|
||||||
libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
|
||||||
|
libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" }
|
||||||
libimagentrytag = { version = "0.9.0", path = "../../../lib/entry/libimagentrytag" }
|
libimagentrytag = { version = "0.9.0", path = "../../../lib/entry/libimagentrytag" }
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
|
|
|
@ -23,8 +23,9 @@ use builtin::header::field_path::FieldPath;
|
||||||
use builtin::header::field_predicate::FieldPredicate;
|
use builtin::header::field_predicate::FieldPredicate;
|
||||||
use builtin::header::field_predicate::Predicate;
|
use builtin::header::field_predicate::Predicate;
|
||||||
use filters::failable::filter::FailableFilter;
|
use filters::failable::filter::FailableFilter;
|
||||||
use error::Result;
|
|
||||||
use error::FilterError as FE;
|
use failure::Fallible as Result;
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ impl FieldEq {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FailableFilter<Entry> for FieldEq {
|
impl FailableFilter<Entry> for FieldEq {
|
||||||
type Error = FE;
|
type Error = Error;
|
||||||
|
|
||||||
fn filter(&self, e: &Entry) -> Result<bool> {
|
fn filter(&self, e: &Entry) -> Result<bool> {
|
||||||
self.filter.filter(e)
|
self.filter.filter(e)
|
||||||
|
|
|
@ -21,8 +21,9 @@ use libimagstore::store::Entry;
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
use filters::failable::filter::FailableFilter;
|
use filters::failable::filter::FailableFilter;
|
||||||
use error::Result;
|
|
||||||
use error::FilterError as FE;
|
use failure::Fallible as Result;
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
use builtin::header::field_path::FieldPath;
|
use builtin::header::field_path::FieldPath;
|
||||||
|
|
||||||
|
@ -41,10 +42,13 @@ impl FieldExists {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FailableFilter<Entry> for FieldExists {
|
impl FailableFilter<Entry> for FieldExists {
|
||||||
type Error = FE;
|
type Error = Error;
|
||||||
|
|
||||||
fn filter(&self, e: &Entry) -> Result<bool> {
|
fn filter(&self, e: &Entry) -> Result<bool> {
|
||||||
e.get_header().read(&self.header_field_path[..]).map_err(FE::from).map(|o| o.is_some())
|
e.get_header()
|
||||||
|
.read(&self.header_field_path[..])
|
||||||
|
.map_err(Error::from)
|
||||||
|
.map(|o| o.is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,9 @@ use builtin::header::field_path::FieldPath;
|
||||||
use builtin::header::field_predicate::FieldPredicate;
|
use builtin::header::field_predicate::FieldPredicate;
|
||||||
use builtin::header::field_predicate::Predicate;
|
use builtin::header::field_predicate::Predicate;
|
||||||
use filters::failable::filter::FailableFilter;
|
use filters::failable::filter::FailableFilter;
|
||||||
use error::Result;
|
|
||||||
use error::FilterError as FE;
|
use failure::Fallible as Result;
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
struct EqGrep{
|
struct EqGrep{
|
||||||
regex: Regex
|
regex: Regex
|
||||||
|
@ -60,7 +61,7 @@ impl FieldGrep {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FailableFilter<Entry> for FieldGrep {
|
impl FailableFilter<Entry> for FieldGrep {
|
||||||
type Error = FE;
|
type Error = Error;
|
||||||
|
|
||||||
fn filter(&self, e: &Entry) -> Result<bool> {
|
fn filter(&self, e: &Entry) -> Result<bool> {
|
||||||
self.filter.filter(e)
|
self.filter.filter(e)
|
||||||
|
|
|
@ -23,8 +23,9 @@ use builtin::header::field_path::FieldPath;
|
||||||
use builtin::header::field_predicate::FieldPredicate;
|
use builtin::header::field_predicate::FieldPredicate;
|
||||||
use builtin::header::field_predicate::Predicate;
|
use builtin::header::field_predicate::Predicate;
|
||||||
use filters::failable::filter::FailableFilter;
|
use filters::failable::filter::FailableFilter;
|
||||||
use error::Result;
|
|
||||||
use error::FilterError as FE;
|
use failure::Fallible as Result;
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ impl FieldGt {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FailableFilter<Entry> for FieldGt {
|
impl FailableFilter<Entry> for FieldGt {
|
||||||
type Error = FE;
|
type Error = Error;
|
||||||
|
|
||||||
fn filter(&self, e: &Entry) -> Result<bool> {
|
fn filter(&self, e: &Entry) -> Result<bool> {
|
||||||
self.filter.filter(e)
|
self.filter.filter(e)
|
||||||
|
|
|
@ -22,8 +22,9 @@ use toml_query::read::TomlValueReadExt;
|
||||||
|
|
||||||
use builtin::header::field_path::FieldPath;
|
use builtin::header::field_path::FieldPath;
|
||||||
use filters::failable::filter::FailableFilter;
|
use filters::failable::filter::FailableFilter;
|
||||||
use error::Result;
|
|
||||||
use error::FilterError as FE;
|
use failure::Fallible as Result;
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ impl FieldIsEmpty {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FailableFilter<Entry> for FieldIsEmpty {
|
impl FailableFilter<Entry> for FieldIsEmpty {
|
||||||
type Error = FE;
|
type Error = Error;
|
||||||
|
|
||||||
fn filter(&self, e: &Entry) -> Result<bool> {
|
fn filter(&self, e: &Entry) -> Result<bool> {
|
||||||
Ok(e
|
Ok(e
|
||||||
|
|
|
@ -23,8 +23,9 @@ use builtin::header::field_path::FieldPath;
|
||||||
use builtin::header::field_predicate::FieldPredicate;
|
use builtin::header::field_predicate::FieldPredicate;
|
||||||
use builtin::header::field_predicate::Predicate;
|
use builtin::header::field_predicate::Predicate;
|
||||||
use filters::failable::filter::FailableFilter;
|
use filters::failable::filter::FailableFilter;
|
||||||
use error::Result;
|
|
||||||
use error::FilterError as FE;
|
use failure::Fallible as Result;
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ impl FieldIsType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FailableFilter<Entry> for FieldIsType {
|
impl FailableFilter<Entry> for FieldIsType {
|
||||||
type Error = FE;
|
type Error = Error;
|
||||||
|
|
||||||
fn filter(&self, e: &Entry) -> Result<bool> {
|
fn filter(&self, e: &Entry) -> Result<bool> {
|
||||||
self.filter.filter(e)
|
self.filter.filter(e)
|
||||||
|
|
|
@ -23,8 +23,9 @@ use builtin::header::field_path::FieldPath;
|
||||||
use builtin::header::field_predicate::FieldPredicate;
|
use builtin::header::field_predicate::FieldPredicate;
|
||||||
use builtin::header::field_predicate::Predicate;
|
use builtin::header::field_predicate::Predicate;
|
||||||
use filters::failable::filter::FailableFilter;
|
use filters::failable::filter::FailableFilter;
|
||||||
use error::Result;
|
|
||||||
use error::FilterError as FE;
|
use failure::Fallible as Result;
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ impl FieldLt {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FailableFilter<Entry> for FieldLt {
|
impl FailableFilter<Entry> for FieldLt {
|
||||||
type Error = FE;
|
type Error = Error;
|
||||||
|
|
||||||
fn filter(&self, e: &Entry) -> Result<bool> {
|
fn filter(&self, e: &Entry) -> Result<bool> {
|
||||||
self.filter.filter(e)
|
self.filter.filter(e)
|
||||||
|
|
|
@ -24,8 +24,9 @@ use toml::Value;
|
||||||
|
|
||||||
use builtin::header::field_path::FieldPath;
|
use builtin::header::field_path::FieldPath;
|
||||||
use filters::failable::filter::FailableFilter;
|
use filters::failable::filter::FailableFilter;
|
||||||
use error::Result;
|
|
||||||
use error::FilterError as FE;
|
use failure::Fallible as Result;
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
pub trait Predicate {
|
pub trait Predicate {
|
||||||
fn evaluate(&self, &Value) -> bool;
|
fn evaluate(&self, &Value) -> bool;
|
||||||
|
@ -53,7 +54,7 @@ impl<P: Predicate> FieldPredicate<P> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: Predicate> FailableFilter<Entry> for FieldPredicate<P> {
|
impl<P: Predicate> FailableFilter<Entry> for FieldPredicate<P> {
|
||||||
type Error = FE;
|
type Error = Error;
|
||||||
|
|
||||||
fn filter(&self, e: &Entry) -> Result<bool> {
|
fn filter(&self, e: &Entry) -> Result<bool> {
|
||||||
Ok(e.get_header()
|
Ok(e.get_header()
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
|
||||||
//
|
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU Lesser General Public
|
|
||||||
// License as published by the Free Software Foundation; version
|
|
||||||
// 2.1 of the License.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
|
||||||
// License along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
//
|
|
||||||
|
|
||||||
error_chain! {
|
|
||||||
|
|
||||||
types {
|
|
||||||
FilterError, FilterErrorKind, ResultExt, Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreign_links {
|
|
||||||
TomlQueryError(::toml_query::error::Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
errors {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -38,16 +38,16 @@ extern crate regex;
|
||||||
extern crate semver;
|
extern crate semver;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
extern crate toml_query;
|
extern crate toml_query;
|
||||||
#[macro_use] extern crate error_chain;
|
extern crate failure;
|
||||||
|
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
extern crate libimagentrytag;
|
extern crate libimagentrytag;
|
||||||
|
extern crate libimagerror;
|
||||||
|
|
||||||
// core functionality modules of the crate,
|
// core functionality modules of the crate,
|
||||||
// these depend only on libimagstore
|
// these depend only on libimagstore
|
||||||
|
|
||||||
pub mod builtin;
|
pub mod builtin;
|
||||||
pub mod error;
|
|
||||||
|
|
||||||
// extended functionality of the crate
|
// extended functionality of the crate
|
||||||
// these depend on other internal libraries than libimagstore and use the upper core modules for
|
// these depend on other internal libraries than libimagstore and use the upper core modules for
|
||||||
|
|
Loading…
Reference in a new issue