Add IntoUrl trait for Link type

With this we can translate a Link type into an URL type from url::Url
This commit is contained in:
Matthias Beyer 2016-07-08 16:29:48 +02:00
parent 3b82311dfd
commit db21fa9dd4

View file

@ -1,5 +1,9 @@
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use result::Result;
use url::Url;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Link(String); pub struct Link(String);
@ -19,3 +23,19 @@ impl DerefMut for Link {
} }
} }
pub trait IntoUrl {
fn into_url(self) -> Result<Url>;
}
impl IntoUrl for Link {
fn into_url(self) -> Result<Url> {
use error::BookmarkErrorKind as BEK;
use error::MapErrInto;
Url::parse(&self[..]).map_err_into(BEK::LinkParsingError)
}
}