From 5a0720e3bb85bb41bb58b884b588ee317a8d8abf Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 12 May 2016 15:10:31 +0200 Subject: [PATCH 01/21] Initial import --- libimagbookmark/Cargo.toml | 6 ++++++ libimagbookmark/src/lib.rs | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 libimagbookmark/Cargo.toml create mode 100644 libimagbookmark/src/lib.rs diff --git a/libimagbookmark/Cargo.toml b/libimagbookmark/Cargo.toml new file mode 100644 index 00000000..897cf5f6 --- /dev/null +++ b/libimagbookmark/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "libimagbookmark" +version = "0.1.0" +authors = ["Matthias Beyer "] + +[dependencies] diff --git a/libimagbookmark/src/lib.rs b/libimagbookmark/src/lib.rs new file mode 100644 index 00000000..cdfbe1aa --- /dev/null +++ b/libimagbookmark/src/lib.rs @@ -0,0 +1,6 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + } +} From 63d2f56a8893934c92a4ae64ad8ba3a1b5cd8f2e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 12 May 2016 15:12:06 +0200 Subject: [PATCH 02/21] Add dependencies --- libimagbookmark/Cargo.toml | 10 ++++++++++ libimagbookmark/src/lib.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libimagbookmark/Cargo.toml b/libimagbookmark/Cargo.toml index 897cf5f6..f4a35358 100644 --- a/libimagbookmark/Cargo.toml +++ b/libimagbookmark/Cargo.toml @@ -4,3 +4,13 @@ version = "0.1.0" authors = ["Matthias Beyer "] [dependencies] +log = "0.3" +semver = "0.2" +url = "1.1" + +[dependencies.libimagstore] +path = "../libimagstore" + +[dependencies.libimagentrylink] +path = "../libimagentrylink" + diff --git a/libimagbookmark/src/lib.rs b/libimagbookmark/src/lib.rs index cdfbe1aa..981b353c 100644 --- a/libimagbookmark/src/lib.rs +++ b/libimagbookmark/src/lib.rs @@ -1,6 +1,6 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - } -} +#[macro_use] extern crate log; +extern crate semver; +extern crate url; + +#[macro_use] extern crate libimagstore; +extern crate libimagentrylink; From 0714d58db065c3242e7593f04da8e26220e1dfec Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 12 May 2016 15:28:24 +0200 Subject: [PATCH 03/21] Add initial codebase --- libimagbookmark/Cargo.toml | 3 ++ libimagbookmark/src/collection.rs | 83 +++++++++++++++++++++++++++++++ libimagbookmark/src/error.rs | 11 ++++ libimagbookmark/src/lib.rs | 7 +++ libimagbookmark/src/result.rs | 6 +++ 5 files changed, 110 insertions(+) create mode 100644 libimagbookmark/src/collection.rs create mode 100644 libimagbookmark/src/error.rs create mode 100644 libimagbookmark/src/result.rs 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> { + 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> { + unimplemented!() + } + + pub fn delete(store: &Store, name: &str) -> Result<()> { + unimplemented!() + } + + pub fn links(&self) -> Result> { + self.fle.get_external_links(&self.store).map_err_into(BEK::LinkError) + } + + pub fn link_entries(&self) -> Result> { + 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 = RResult; + From f2cc233c37b002ccecfd8f132998e712fd021c89 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 00:11:27 +0200 Subject: [PATCH 04/21] Add error kind if collection cannot be found --- libimagbookmark/src/error.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libimagbookmark/src/error.rs b/libimagbookmark/src/error.rs index 7f80e1a9..e13fbe50 100644 --- a/libimagbookmark/src/error.rs +++ b/libimagbookmark/src/error.rs @@ -1,7 +1,8 @@ generate_error_module!( generate_error_types!(BookmarkError, BookmarkErrorKind, - StoreReadError => "Store read error", - LinkError => "Link error" + StoreReadError => "Store read error", + LinkError => "Link error", + CollectionNotFound => "Link-Collection not found" ); ); From ed1eea053acd6766f79fef3a3600e8fff5c24d0e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 00:11:54 +0200 Subject: [PATCH 05/21] Impl BookmarkCollection::get() --- libimagbookmark/src/collection.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index 3316d562..593990a5 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -19,6 +19,7 @@ use libimagstore::store::FileLockEntry; use libimagentrylink::external::ExternalLinker; use libimagentrylink::internal::InternalLinker; use libimagentrylink::internal::Link; +use libimagerror::into::IntoError; use url::Url; pub struct BookmarkCollection<'a> { @@ -58,8 +59,19 @@ impl<'a> BookmarkCollection<'a> { .map_err_into(BEK::StoreReadError) } - pub fn open(store: &Store, name: &str) -> Result> { - unimplemented!() + pub fn get(store: &'a Store, name: &str) -> Result> { + let id = ModuleEntryPath::new(name).into_storeid(); + store.get(id) + .map_err_into(BEK::StoreReadError) + .and_then(|fle| { + match fle { + None => Err(BEK::CollectionNotFound.into_error()), + Some(e) => Ok(BookmarkCollection { + fle: e, + store: store, + }), + } + }) } pub fn delete(store: &Store, name: &str) -> Result<()> { From 5fa189fb4e01cf07b832224f3cf1ff6cec74ec4e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 00:12:05 +0200 Subject: [PATCH 06/21] Impl BookmarkCollection::delete() --- libimagbookmark/src/collection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index 593990a5..b1def1d7 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -75,7 +75,7 @@ impl<'a> BookmarkCollection<'a> { } pub fn delete(store: &Store, name: &str) -> Result<()> { - unimplemented!() + store.delete(ModuleEntryPath::new(name).into_storeid()).map_err_into(BEK::StoreReadError) } pub fn links(&self) -> Result> { From eb47f084792170a64809a14c6b0d240c67c0de56 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 00:23:56 +0200 Subject: [PATCH 07/21] Add depenndency: regex --- libimagbookmark/Cargo.toml | 1 + libimagbookmark/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/libimagbookmark/Cargo.toml b/libimagbookmark/Cargo.toml index 7ced32c1..2d005855 100644 --- a/libimagbookmark/Cargo.toml +++ b/libimagbookmark/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Matthias Beyer "] log = "0.3" semver = "0.2" url = "1.1" +regex = "0.1" [dependencies.libimagstore] path = "../libimagstore" diff --git a/libimagbookmark/src/lib.rs b/libimagbookmark/src/lib.rs index 4c42547a..a06fca54 100644 --- a/libimagbookmark/src/lib.rs +++ b/libimagbookmark/src/lib.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate log; extern crate semver; extern crate url; +extern crate regex; #[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagerror; From ee51de088a8d958048650082714f65428d41b012 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 00:27:35 +0200 Subject: [PATCH 08/21] Add Link type --- libimagbookmark/src/lib.rs | 1 + libimagbookmark/src/link.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 libimagbookmark/src/link.rs diff --git a/libimagbookmark/src/lib.rs b/libimagbookmark/src/lib.rs index a06fca54..e33a2466 100644 --- a/libimagbookmark/src/lib.rs +++ b/libimagbookmark/src/lib.rs @@ -11,4 +11,5 @@ module_entry_path_mod!("bookmark", "0.1.0"); pub mod collection; pub mod error; +pub mod link; pub mod result; diff --git a/libimagbookmark/src/link.rs b/libimagbookmark/src/link.rs new file mode 100644 index 00000000..6b835bdc --- /dev/null +++ b/libimagbookmark/src/link.rs @@ -0,0 +1,21 @@ +use std::ops::{Deref, DerefMut} + +#[derive(Debug, Clone)] +pub struct Link(String); + +impl Deref for Link { + type Target = String; + + fn deref(&self) => &String { + &self.0 + } + +} + +impl DerefMut for Link { + + fn deref_mut(&mut self) => &mut String { + &mut self.0 + } + +} From 9231cf5fb7765d88b5d005683e27f009472edb97 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 00:27:45 +0200 Subject: [PATCH 09/21] Add interface for working with BookmarkCollection Oh my god I'm so drunk right now. It's 0030 and I had dinner at around 1800 yesterday and then I just drank like... two Mate and maybe 1L of water... and now I drank 0.33L beer and I'm drunk as fuck... just wanted to share. I hope this commit still makes sense... I'm not sure, I should definitively review this tomorrow. So... maybe I can do some more. Btw., I just saw "The Martian" - the movie, you know. Oh my god, I love Matt Damon - I think he's a really nice actor, actually. I probably shouldn't put this into the commit message, I know... Just wanted to have some fun here.. sorry. --- libimagbookmark/src/collection.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index b1def1d7..b0ed38de 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -18,10 +18,12 @@ use libimagstore::storeid::IntoStoreId; use libimagstore::store::FileLockEntry; use libimagentrylink::external::ExternalLinker; use libimagentrylink::internal::InternalLinker; -use libimagentrylink::internal::Link; +use libimagentrylink::internal::Link as StoreLink; use libimagerror::into::IntoError; use url::Url; +use link::Link; + pub struct BookmarkCollection<'a> { fle: FileLockEntry<'a>, store: &'a Store, @@ -82,7 +84,7 @@ impl<'a> BookmarkCollection<'a> { self.fle.get_external_links(&self.store).map_err_into(BEK::LinkError) } - pub fn link_entries(&self) -> Result> { + pub fn link_entries(&self) -> Result> { use libimagentrylink::external::is_external_link_storeid; self.fle @@ -91,5 +93,21 @@ impl<'a> BookmarkCollection<'a> { .map_err_into(BEK::StoreReadError) } + pub fn add_link(&self, l: Link) -> Result<()> { + unimplemented!() + } + + pub fn get_link(&self, l: Link) -> Result { + unimplemented!() + } + + pub fn get_links_matching(&self, r: Regex) -> Result { + unimplemented!() + } + + pub fn remove_link(&self, l: Link) -> Result<()> { + unimplemented!() + } + } From 3b485febe490eec2043ec52d13b63a86d9e2f47c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:20:35 +0200 Subject: [PATCH 10/21] fixup! Add Link type --- libimagbookmark/src/link.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libimagbookmark/src/link.rs b/libimagbookmark/src/link.rs index 6b835bdc..3dd3aeb0 100644 --- a/libimagbookmark/src/link.rs +++ b/libimagbookmark/src/link.rs @@ -1,4 +1,4 @@ -use std::ops::{Deref, DerefMut} +use std::ops::{Deref, DerefMut}; #[derive(Debug, Clone)] pub struct Link(String); @@ -6,7 +6,7 @@ pub struct Link(String); impl Deref for Link { type Target = String; - fn deref(&self) => &String { + fn deref(&self) -> &String { &self.0 } @@ -14,7 +14,7 @@ impl Deref for Link { impl DerefMut for Link { - fn deref_mut(&mut self) => &mut String { + fn deref_mut(&mut self) -> &mut String { &mut self.0 } From 22e07d171b8bfc5a005c7c67804a3db6daa1cd60 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:21:24 +0200 Subject: [PATCH 11/21] fixup! Add depenndency: regex --- libimagbookmark/src/collection.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index b0ed38de..a6e29ee0 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -7,6 +7,8 @@ use std::ops::Deref; use std::ops::DerefMut; +use regex::Regex; + use error::BookmarkError as BE; use error::BookmarkErrorKind as BEK; use error::MapErrInto; From 3b82311dfd7ddd7c56b995086a0984b44f1e6d92 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:29:06 +0200 Subject: [PATCH 12/21] Add more specific linking error kinds --- libimagbookmark/src/error.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libimagbookmark/src/error.rs b/libimagbookmark/src/error.rs index e13fbe50..79849d9e 100644 --- a/libimagbookmark/src/error.rs +++ b/libimagbookmark/src/error.rs @@ -2,6 +2,8 @@ generate_error_module!( generate_error_types!(BookmarkError, BookmarkErrorKind, StoreReadError => "Store read error", LinkError => "Link error", + LinkParsingError => "Link parsing error", + LinkingError => "Error while linking", CollectionNotFound => "Link-Collection not found" ); ); From db21fa9dd4c3d30888da501e2919fe900eb4c733 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:29:48 +0200 Subject: [PATCH 13/21] Add IntoUrl trait for Link type With this we can translate a Link type into an URL type from url::Url --- libimagbookmark/src/link.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libimagbookmark/src/link.rs b/libimagbookmark/src/link.rs index 3dd3aeb0..7dbab981 100644 --- a/libimagbookmark/src/link.rs +++ b/libimagbookmark/src/link.rs @@ -1,5 +1,9 @@ use std::ops::{Deref, DerefMut}; +use result::Result; + +use url::Url; + #[derive(Debug, Clone)] pub struct Link(String); @@ -19,3 +23,19 @@ impl DerefMut for Link { } } + +pub trait IntoUrl { + fn into_url(self) -> Result; +} + +impl IntoUrl for Link { + + fn into_url(self) -> Result { + use error::BookmarkErrorKind as BEK; + use error::MapErrInto; + + Url::parse(&self[..]).map_err_into(BEK::LinkParsingError) + } + +} + From 2ed07d4f7d088a2de7927971880503f931ca0cf8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:30:11 +0200 Subject: [PATCH 14/21] Impl BookmarkCollection::add_link() --- libimagbookmark/src/collection.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index a6e29ee0..2a820c29 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -95,8 +95,12 @@ impl<'a> BookmarkCollection<'a> { .map_err_into(BEK::StoreReadError) } - pub fn add_link(&self, l: Link) -> Result<()> { - unimplemented!() + pub fn add_link(&mut self, l: Link) -> Result<()> { + use link::IntoUrl; + + l.into_url() + .and_then(|url| self.add_external_link(self.store, url).map_err_into(BEK::LinkingError)) + .map_err_into(BEK::LinkError) } pub fn get_link(&self, l: Link) -> Result { From 749f08ca66de7715a6e2008f3e3037e6b220f285 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:30:50 +0200 Subject: [PATCH 15/21] fixup for 9231cf5f --- libimagbookmark/src/collection.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index 2a820c29..bdee34a2 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -103,10 +103,6 @@ impl<'a> BookmarkCollection<'a> { .map_err_into(BEK::LinkError) } - pub fn get_link(&self, l: Link) -> Result { - unimplemented!() - } - pub fn get_links_matching(&self, r: Regex) -> Result { unimplemented!() } From ee53a28c9a6b7a4634b996157880e35f83476b89 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:40:09 +0200 Subject: [PATCH 16/21] Impl From for Link --- libimagbookmark/src/link.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libimagbookmark/src/link.rs b/libimagbookmark/src/link.rs index 7dbab981..9ea53c0c 100644 --- a/libimagbookmark/src/link.rs +++ b/libimagbookmark/src/link.rs @@ -7,6 +7,14 @@ use url::Url; #[derive(Debug, Clone)] pub struct Link(String); +impl From for Link { + + fn from(s: String) -> Link { + Link(s) + } + +} + impl Deref for Link { type Target = String; From 2e49947013f75ef0d008e783bad1126801e307b9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:40:28 +0200 Subject: [PATCH 17/21] Impl BookmarkCollection::get_links_matching() --- libimagbookmark/src/collection.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index bdee34a2..bd6b8b22 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -103,8 +103,16 @@ impl<'a> BookmarkCollection<'a> { .map_err_into(BEK::LinkError) } - pub fn get_links_matching(&self, r: Regex) -> Result { - unimplemented!() + pub fn get_links_matching(&self, r: Regex) -> Result> { + self.get_external_links(self.store) + .map_err_into(BEK::LinkError) + .map(|v| { + v.into_iter() + .map(Url::into_string) + .filter(|urlstr| r.is_match(&urlstr[..])) + .map(Link::from) + .next() + }) } pub fn remove_link(&self, l: Link) -> Result<()> { From 2c93c8b98f64b3c0df19272752b685d225a31d95 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:41:37 +0200 Subject: [PATCH 18/21] fixup! Impl BookmarkCollection::get_links_matching() --- libimagbookmark/src/collection.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index bd6b8b22..f5b0e4d4 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -103,7 +103,7 @@ impl<'a> BookmarkCollection<'a> { .map_err_into(BEK::LinkError) } - pub fn get_links_matching(&self, r: Regex) -> Result> { + pub fn get_links_matching(&self, r: Regex) -> Result> { self.get_external_links(self.store) .map_err_into(BEK::LinkError) .map(|v| { @@ -111,7 +111,7 @@ impl<'a> BookmarkCollection<'a> { .map(Url::into_string) .filter(|urlstr| r.is_match(&urlstr[..])) .map(Link::from) - .next() + .collect() }) } From d5c6af884b133f7fdf3affe89a0eb64bce9f21f9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:54:05 +0200 Subject: [PATCH 19/21] Remove unneeded import --- libimagbookmark/src/collection.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index f5b0e4d4..ae9f66e2 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -9,7 +9,6 @@ use std::ops::DerefMut; use regex::Regex; -use error::BookmarkError as BE; use error::BookmarkErrorKind as BEK; use error::MapErrInto; use result::Result; From 91e3b58f3eb9b5ad78954c0f42812bd5e248340c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 16:54:27 +0200 Subject: [PATCH 20/21] Implement BookmarkCollection::remove_link() --- libimagbookmark/src/collection.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libimagbookmark/src/collection.rs b/libimagbookmark/src/collection.rs index ae9f66e2..b7fc4459 100644 --- a/libimagbookmark/src/collection.rs +++ b/libimagbookmark/src/collection.rs @@ -114,8 +114,14 @@ impl<'a> BookmarkCollection<'a> { }) } - pub fn remove_link(&self, l: Link) -> Result<()> { - unimplemented!() + pub fn remove_link(&mut self, l: Link) -> Result<()> { + use link::IntoUrl; + + l.into_url() + .and_then(|url| { + self.remove_external_link(self.store, url).map_err_into(BEK::LinkingError) + }) + .map_err_into(BEK::LinkError) } } From 437b3133ccc35badc08527e0eaa76200ca09fb20 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 8 Jul 2016 21:41:11 +0200 Subject: [PATCH 21/21] impl From<&'a str> for Link --- libimagbookmark/src/link.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libimagbookmark/src/link.rs b/libimagbookmark/src/link.rs index 9ea53c0c..078d45d7 100644 --- a/libimagbookmark/src/link.rs +++ b/libimagbookmark/src/link.rs @@ -15,6 +15,14 @@ impl From for Link { } +impl<'a> From<&'a str> for Link { + + fn from(s: &'a str) -> Link { + Link(String::from(s)) + } + +} + impl Deref for Link { type Target = String;