Add (external) link validation
This commit is contained in:
parent
cb288eb868
commit
695ee9df9b
3 changed files with 11 additions and 0 deletions
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#[macro_use] extern crate log;
|
||||
extern crate toml;
|
||||
extern crate url;
|
||||
|
||||
extern crate libimagstore;
|
||||
|
||||
|
|
Loading…
Reference in a new issue