imag/libimagbookmark/src/link.rs

58 lines
805 B
Rust
Raw Normal View History

2016-07-08 14:20:35 +00:00
use std::ops::{Deref, DerefMut};
2016-07-07 22:27:35 +00:00
use result::Result;
use url::Url;
2016-07-07 22:27:35 +00:00
#[derive(Debug, Clone)]
pub struct Link(String);
2016-07-08 14:40:09 +00:00
impl From<String> for Link {
fn from(s: String) -> Link {
Link(s)
}
}
2016-07-08 19:41:11 +00:00
impl<'a> From<&'a str> for Link {
fn from(s: &'a str) -> Link {
Link(String::from(s))
}
}
2016-07-07 22:27:35 +00:00
impl Deref for Link {
type Target = String;
2016-07-08 14:20:35 +00:00
fn deref(&self) -> &String {
2016-07-07 22:27:35 +00:00
&self.0
}
}
impl DerefMut for Link {
2016-07-08 14:20:35 +00:00
fn deref_mut(&mut self) -> &mut String {
2016-07-07 22:27:35 +00:00
&mut self.0
}
}
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)
}
}