From 3f5aded44643286f8ccb8d4c094601aee872081b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 13 Oct 2016 16:05:39 +0200 Subject: [PATCH] Add Annotateable::annotations() --- libimagannotation/src/annotation.rs | 25 +++++++++++++++++++++++++ libimagannotation/src/lib.rs | 4 +++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libimagannotation/src/annotation.rs b/libimagannotation/src/annotation.rs index 5e2ad2fc..3d0d11e9 100644 --- a/libimagannotation/src/annotation.rs +++ b/libimagannotation/src/annotation.rs @@ -44,6 +44,11 @@ pub trait Annotateable { /// The `pg` is a AnnotationPathGenerator object which is used to generate a StoreId fn annotate_with_path_generator(&self, store: &Store, pg: &AnnotationPathGenerator) -> Result; + /// List annotations of a Annotateable + /// + /// This lists only annotations that are generated via the `DefaultAnnotationPathGenerator` + fn annotations(&self) -> Result>; + } /// A AnnotationPathGenerator generates a unique path for the annotation to be generated. @@ -80,4 +85,24 @@ impl Annotateable for FileLockEntry { }) .map(Annotation) } + + /// Get the annotations of a FileLockEntry + /// + /// Returns the pathes to the annotations, not the annotations itself. + fn annotations(&self) -> Result> { + self.get_internal_links() + .map_err_into(AEK::LinkError) + .map(|v| v.iter_into() + .filter(|id| id.components() + .next() + .map(|fst| match fst { + Component::Normal(ref s) => s == ANNOTATION_COLLECTION_NAME, + _ => false, + }) + .unwrap_or(false) + ) + .collect::>(); + ) + } + } diff --git a/libimagannotation/src/lib.rs b/libimagannotation/src/lib.rs index 90eed07d..369f2515 100644 --- a/libimagannotation/src/lib.rs +++ b/libimagannotation/src/lib.rs @@ -24,7 +24,9 @@ extern crate uuid; extern crate libimaglink; extern crate libimagutil; -module_entry_path_mod!("annotation"); +static ANNOTATION_COLLECTION_NAME : &str = "annotation"; + +module_entry_path_mod!(ANNOTATION_COLLECTION_NAME); pub mod annotation; pub mod error;