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

View file

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

View file

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