diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-12 15:28:24 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-07-08 00:01:44 +0200 |
commit | 0714d58db065c3242e7593f04da8e26220e1dfec (patch) | |
tree | 136376e0794e017e7c6e1c33f43c3e9815a9c367 /libimagbookmark | |
parent | 63d2f56a8893934c92a4ae64ad8ba3a1b5cd8f2e (diff) |
Add initial codebase
Diffstat (limited to 'libimagbookmark')
-rw-r--r-- | libimagbookmark/Cargo.toml | 3 | ||||
-rw-r--r-- | libimagbookmark/src/collection.rs | 83 | ||||
-rw-r--r-- | libimagbookmark/src/error.rs | 11 | ||||
-rw-r--r-- | libimagbookmark/src/lib.rs | 7 | ||||
-rw-r--r-- | libimagbookmark/src/result.rs | 6 |
5 files changed, 110 insertions, 0 deletions
diff --git a/libimagbookmark/Cargo.toml b/libimagbookmark/Cargo.toml index f4a35358..7ced32c1 100644 --- a/libimagbookmark/Cargo.toml +++ b/libimagbookmark/Cargo.toml @@ -11,6 +11,9 @@ url = "1.1" [dependencies.libimagstore] path = "../libimagstore" +[dependencies.libimagerror] +path = "../libimagerror" + [dependencies.libimagentrylink] path = "../libimagentrylink" diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs new file mode 100644 index 00000000..3316d562 --- /dev/null +++ b/libimagbookmark/src/collection.rs @@ -0,0 +1,83 @@ +//! BookmarkCollection module +//! +//! A BookmarkCollection is nothing more than a simple store entry. One can simply call functions +//! from the libimagentrylink::external::ExternalLinker trait on this to generate external links. +//! +//! The BookmarkCollection type offers helper functions to get all links or such things. +use std::ops::Deref; +use std::ops::DerefMut; + +use error::BookmarkError as BE; +use error::BookmarkErrorKind as BEK; +use error::MapErrInto; +use result::Result; +use module_path::ModuleEntryPath; + +use libimagstore::store::Store; +use libimagstore::storeid::IntoStoreId; +use libimagstore::store::FileLockEntry; +use libimagentrylink::external::ExternalLinker; +use libimagentrylink::internal::InternalLinker; +use libimagentrylink::internal::Link; +use url::Url; + +pub struct BookmarkCollection<'a> { + fle: FileLockEntry<'a>, + store: &'a Store, +} + +/// {Internal, External}Linker is implemented as Deref is implemented +impl<'a> Deref for BookmarkCollection<'a> { + type Target = FileLockEntry<'a>; + + fn deref(&self) -> &FileLockEntry<'a> { + &self.fle + } + +} + +impl<'a> DerefMut for BookmarkCollection<'a> { + + fn deref_mut(&mut self) -> &mut FileLockEntry<'a> { + &mut self.fle + } + +} + +impl<'a> BookmarkCollection<'a> { + + pub fn new(store: &'a Store, name: &str) -> Result<BookmarkCollection<'a>> { + let id = ModuleEntryPath::new(name).into_storeid(); + store.create(id) + .map(|fle| { + BookmarkCollection { + fle: fle, + store: store, + } + }) + .map_err_into(BEK::StoreReadError) + } + + pub fn open(store: &Store, name: &str) -> Result<BookmarkCollection<'a>> { + unimplemented!() + } + + pub fn delete(store: &Store, name: &str) -> Result<()> { + unimplemented!() + } + + pub fn links(&self) -> Result<Vec<Url>> { + self.fle.get_external_links(&self.store).map_err_into(BEK::LinkError) + } + + pub fn link_entries(&self) -> Result<Vec<Link>> { + use libimagentrylink::external::is_external_link_storeid; + + self.fle + .get_internal_links() + .map(|v| v.into_iter().filter(|id| is_external_link_storeid(id)).collect()) + .map_err_into(BEK::StoreReadError) + } + +} + diff --git a/libimagbookmark/src/error.rs b/libimagbookmark/src/error.rs new file mode 100644 index 00000000..7f80e1a9 --- /dev/null +++ b/libimagbookmark/src/error.rs @@ -0,0 +1,11 @@ +generate_error_module!( + generate_error_types!(BookmarkError, BookmarkErrorKind, + StoreReadError => "Store read error", + LinkError => "Link error" + ); +); + +pub use self::error::BookmarkError; +pub use self::error::BookmarkErrorKind; +pub use self::error::MapErrInto; + diff --git a/libimagbookmark/src/lib.rs b/libimagbookmark/src/lib.rs index 981b353c..4c42547a 100644 --- a/libimagbookmark/src/lib.rs +++ b/libimagbookmark/src/lib.rs @@ -3,4 +3,11 @@ extern crate semver; extern crate url; #[macro_use] extern crate libimagstore; +#[macro_use] extern crate libimagerror; extern crate libimagentrylink; + +module_entry_path_mod!("bookmark", "0.1.0"); + +pub mod collection; +pub mod error; +pub mod result; diff --git a/libimagbookmark/src/result.rs b/libimagbookmark/src/result.rs new file mode 100644 index 00000000..265fec97 --- /dev/null +++ b/libimagbookmark/src/result.rs @@ -0,0 +1,6 @@ +use std::result::Result as RResult; + +use error::BookmarkError; + +pub type Result<T> = RResult<T, BookmarkError>; + |