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
1 changed files with 20 additions and 0 deletions

View File

@ -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<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)
}
}