Use libimagentryutil::isa::Is in libimagentryannotation

This commit is contained in:
Matthias Beyer 2018-01-03 17:21:51 +01:00
parent a7c8fa1212
commit 00d09e618e
4 changed files with 12 additions and 7 deletions

View file

@ -24,3 +24,4 @@ error-chain = "0.11"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }
libimagentrylink = { version = "0.6.0", path = "../../../lib/entry/libimagentrylink" } libimagentrylink = { version = "0.6.0", path = "../../../lib/entry/libimagentrylink" }
libimagentryutil = { version = "0.6.0", path = "../../../lib/entry/libimagentryutil" }

View file

@ -25,6 +25,8 @@ use libimagstore::store::Store;
use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::IntoStoreId;
use libimagstore::storeid::StoreIdIterator; use libimagstore::storeid::StoreIdIterator;
use libimagentrylink::internal::InternalLinker; use libimagentrylink::internal::InternalLinker;
use libimagentryutil::isa::Is;
use libimagentryutil::isa::IsKindHeaderPathProvider;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
@ -43,6 +45,8 @@ pub trait Annotateable {
fn is_annotation(&self) -> Result<bool>; fn is_annotation(&self) -> Result<bool>;
} }
provide_kindflag_path!(IsAnnotation, "annotation.is_annotation");
impl Annotateable for Entry { impl Annotateable for Entry {
/// Annotate an entry, returns the new entry which is used to annotate /// Annotate an entry, returns the new entry which is used to annotate
@ -52,9 +56,10 @@ impl Annotateable for Entry {
.map_err(From::from) .map_err(From::from)
.and_then(|mut anno| { .and_then(|mut anno| {
{ {
let header = anno.get_header_mut(); let _ = anno.set_isflag::<IsAnnotation>()?;
header.insert("annotation.is_annotation", Value::Boolean(true))?; let _ = anno
header.insert("annotation.name", Value::String(String::from(ann_name)))?; .get_header_mut()
.insert("annotation.name", Value::String(String::from(ann_name)))?;
} }
Ok(anno) Ok(anno)
}) })
@ -96,10 +101,7 @@ impl Annotateable for Entry {
} }
fn is_annotation(&self) -> Result<bool> { fn is_annotation(&self) -> Result<bool> {
self.get_header() self.is::<IsAnnotation>().map_err(From::from)
.read("annotation.is_annotation")?
.map(|val| val.as_bool().unwrap_or(false))
.ok_or(AE::from_kind(AEK::HeaderTypeError))
} }
} }

View file

@ -25,6 +25,7 @@ error_chain! {
links { links {
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind); StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind); LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind);
EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind);
} }
foreign_links { foreign_links {

View file

@ -42,6 +42,7 @@ extern crate toml_query;
#[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagstore;
extern crate libimagerror; extern crate libimagerror;
extern crate libimagentrylink; extern crate libimagentrylink;
#[macro_use] extern crate libimagentryutil;
module_entry_path_mod!("annotations"); module_entry_path_mod!("annotations");