From ec855fefc70f34b6299d46afc423546d8a6c278f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 12 Oct 2017 17:56:43 +0200 Subject: [PATCH] Remove dependency on libimagnotes --- lib/entry/libimagentryannotation/Cargo.toml | 1 - .../src/annotation_fetcher.rs | 27 +++++++------------ lib/entry/libimagentryannotation/src/error.rs | 5 ++++ lib/entry/libimagentryannotation/src/lib.rs | 1 - 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/entry/libimagentryannotation/Cargo.toml b/lib/entry/libimagentryannotation/Cargo.toml index 15302c52..fae57cd9 100644 --- a/lib/entry/libimagentryannotation/Cargo.toml +++ b/lib/entry/libimagentryannotation/Cargo.toml @@ -17,5 +17,4 @@ error-chain = "0.10" libimagstore = { version = "0.5.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.5.0", path = "../../../lib/core/libimagerror" } -libimagnotes = { version = "0.5.0", path = "../../../lib/domain/libimagnotes" } libimagentrylink = { version = "0.5.0", path = "../../../lib/entry/libimagentrylink" } diff --git a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs index afdec887..06d8f00e 100644 --- a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs +++ b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs @@ -20,12 +20,9 @@ use libimagstore::store::Entry; use libimagstore::store::Store; use libimagentrylink::internal::InternalLinker; -use libimagnotes::notestore::NoteStore; -use libimagnotes::iter::NoteIterator; use libimagstore::storeid::StoreIdIterator; use error::Result; -use error::AnnotationErrorKind as AEK; use error::ResultExt; use self::iter::*; @@ -40,12 +37,10 @@ pub trait AnnotationFetcher<'a> { impl<'a> AnnotationFetcher<'a> for Store { - /// Wrapper around `Note::all_notes()` of `libimagnotes` which filters out normal notes and - /// leaves only annotations in the iterator. fn all_annotations(&'a self) -> Result> { - NoteStore::all_notes(self) + self.retrieve_for_module("annotations") .map(|iter| AnnotationIter::new(iter, self)) - .chain_err(|| AEK::StoreReadError) + .map_err(Into::into) } /// Get all annotations (in an iterator) for an entry @@ -57,9 +52,8 @@ impl<'a> AnnotationFetcher<'a> for Store { /// entry, but should normally be not that heavy. fn annotations_for_entry(&'a self, entry: &Entry) -> Result> { entry.get_internal_links() - .chain_err(|| AEK::StoreReadError) + .map_err(Into::into) .map(|iter| StoreIdIterator::new(Box::new(iter.map(|e| e.get_store_id().clone())))) - .map(NoteIterator::new) .map(|i| AnnotationIter::new(i, self)) } @@ -67,12 +61,11 @@ impl<'a> AnnotationFetcher<'a> for Store { pub mod iter { use toml::Value; - use toml_query::read::TomlValueReadExt; - use libimagnotes::iter::NoteIterator; use libimagstore::store::Store; use libimagstore::store::FileLockEntry; + use libimagstore::storeid::StoreIdIterator; use error::Result; use error::AnnotationErrorKind as AEK; @@ -80,12 +73,12 @@ pub mod iter { use error::ResultExt; #[derive(Debug)] - pub struct AnnotationIter<'a>(NoteIterator, &'a Store); + pub struct AnnotationIter<'a>(StoreIdIterator, &'a Store); impl<'a> AnnotationIter<'a> { - pub fn new(noteiter: NoteIterator, store: &'a Store) -> AnnotationIter<'a> { - AnnotationIter(noteiter, store) + pub fn new(iter: StoreIdIterator, store: &'a Store) -> AnnotationIter<'a> { + AnnotationIter(iter, store) } } @@ -96,10 +89,10 @@ pub mod iter { fn next(&mut self) -> Option { loop { match self.0.next().map(|id| self.1.get(id)) { - Some(Ok(Some(note))) => { - match note.get_header().read("annotation.is_annotation") { + Some(Ok(Some(entry))) => { + match entry.get_header().read("annotation.is_annotation") { Ok(None) => continue, // not an annotation - Ok(Some(&Value::Boolean(true))) => return Some(Ok(note)), + Ok(Some(&Value::Boolean(true))) => return Some(Ok(entry)), Ok(Some(_)) => return Some(Err(AE::from_kind(AEK::HeaderTypeError))), Err(e) => return Some(Err(e).chain_err(|| AEK::HeaderReadError)), } diff --git a/lib/entry/libimagentryannotation/src/error.rs b/lib/entry/libimagentryannotation/src/error.rs index 8a349b71..8d26e2f1 100644 --- a/lib/entry/libimagentryannotation/src/error.rs +++ b/lib/entry/libimagentryannotation/src/error.rs @@ -22,6 +22,11 @@ error_chain! { AnnotationError, AnnotationErrorKind, ResultExt, Result; } + links { + StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind); + LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind); + } + errors { StoreReadError { description("Store read error") diff --git a/lib/entry/libimagentryannotation/src/lib.rs b/lib/entry/libimagentryannotation/src/lib.rs index bd1e9ed5..dfd2ab52 100644 --- a/lib/entry/libimagentryannotation/src/lib.rs +++ b/lib/entry/libimagentryannotation/src/lib.rs @@ -42,7 +42,6 @@ extern crate toml_query; extern crate libimagerror; extern crate libimagstore; extern crate libimagentrylink; -extern crate libimagnotes; pub mod annotateable; pub mod annotation_fetcher;