From fdee97c9a19cc7b3b64ca3b67fbe873ae9278c27 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 26 Jun 2017 19:28:36 +0200 Subject: [PATCH] Add Annotateable::is_annotation() --- libimagannotation/src/annotateable.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libimagannotation/src/annotateable.rs b/libimagannotation/src/annotateable.rs index 698773cb..8827916a 100644 --- a/libimagannotation/src/annotateable.rs +++ b/libimagannotation/src/annotateable.rs @@ -40,6 +40,9 @@ pub trait Annotateable { /// A new annotation also has the field `annotation.is_annotation` set to `true`. fn annotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result>; + /// Check whether an entry is an annotation + fn is_annotation(&self) -> Result; + } impl Annotateable for Entry { @@ -66,5 +69,16 @@ impl Annotateable for Entry { }) } + fn is_annotation(&self) -> Result { + self.get_header() + .read("annotation.is_annotation") + .map_err_into(AEK::StoreReadError) + .and_then(|res| match res { + Some(Value::Boolean(b)) => Ok(b), + None => Ok(false), + _ => Err(AEK::HeaderTypeError.into_error()), + }) + } + }