Add Annotateable::annotations()

This commit is contained in:
Matthias Beyer 2016-10-13 16:05:39 +02:00
parent cb45c91fa5
commit 3f5aded446
2 changed files with 28 additions and 1 deletions

View file

@ -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<Annotation>;
/// List annotations of a Annotateable
///
/// This lists only annotations that are generated via the `DefaultAnnotationPathGenerator`
fn annotations(&self) -> Result<Vec<StoreId>>;
}
/// 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<Vec<StoreId>> {
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::<Vec<StoreId>>();
)
}
}

View file

@ -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;