diff --git a/libimaglink/Cargo.toml b/libimaglink/Cargo.toml index 22d20f61..54c3b15a 100644 --- a/libimaglink/Cargo.toml +++ b/libimaglink/Cargo.toml @@ -6,6 +6,7 @@ authors = ["Matthias Beyer "] [dependencies] log = "0.3.4" toml = "0.1.27" +url = "0.5.5" [dependencies.libimagstore] path = "../libimagstore" diff --git a/libimaglink/src/external.rs b/libimaglink/src/external.rs index b9168b20..59d6c0e1 100644 --- a/libimaglink/src/external.rs +++ b/libimaglink/src/external.rs @@ -8,6 +8,7 @@ use result::Result; use toml::Value; use toml::Table; +use url::Url; #[derive(PartialOrd, Ord, Eq, PartialEq, Clone, Debug)] pub struct Link { @@ -20,6 +21,10 @@ impl Link { Link { link: s } } + pub fn is_valid(&self) -> bool { + Url::parse(&self.link[..]).is_ok() + } + } #[derive(Eq, PartialEq, Clone, Debug)] @@ -41,6 +46,10 @@ impl Links { self.links.retain(|link| l != link.clone()); } + pub fn all_valid(&self) -> bool { + self.links.iter().all(|l| l.is_valid()) + } + } impl Into for Link { diff --git a/libimaglink/src/lib.rs b/libimaglink/src/lib.rs index 0ea1f956..abb3a7ab 100644 --- a/libimaglink/src/lib.rs +++ b/libimaglink/src/lib.rs @@ -1,5 +1,6 @@ #[macro_use] extern crate log; extern crate toml; +extern crate url; extern crate libimagstore;