Add (external) link validation

This commit is contained in:
Matthias Beyer 2016-02-23 11:50:42 +01:00
parent cb288eb868
commit 695ee9df9b
3 changed files with 11 additions and 0 deletions

View file

@ -6,6 +6,7 @@ authors = ["Matthias Beyer <mail@beyermatthias.de>"]
[dependencies]
log = "0.3.4"
toml = "0.1.27"
url = "0.5.5"
[dependencies.libimagstore]
path = "../libimagstore"

View file

@ -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<String> for Link {

View file

@ -1,5 +1,6 @@
#[macro_use] extern crate log;
extern crate toml;
extern crate url;
extern crate libimagstore;