diff --git a/src/request.rs b/src/request.rs index d50ff65..c836efc 100644 --- a/src/request.rs +++ b/src/request.rs @@ -20,13 +20,10 @@ pub struct Request { impl RequestBase for Request { fn new(url: T) -> Result { - match url.into_url() { - Ok(url_parsed) => Ok(Request { - url: url_parsed, - method: Method::GET, - }), - Err(error) => Err(error), - } + url.into_url().map(|url_parsed| Request { + url: url_parsed, + method: Method::GET, + }) } fn launch(self) -> response::Response { diff --git a/src/response.rs b/src/response.rs index 8c15fbd..ed94a1f 100644 --- a/src/response.rs +++ b/src/response.rs @@ -13,7 +13,7 @@ pub struct Response { } impl SelectorBase for Response { - fn from_html(_: String) -> Self { + fn from_html>(_: S) -> Self { unimplemented!() } diff --git a/src/selector.rs b/src/selector.rs index 4e19690..2aac23c 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -1,5 +1,5 @@ pub trait SelectorBase { - fn from_html(html: String) -> Self; + fn from_html>(html: S) -> Self; fn html(&self) -> String; @@ -58,9 +58,9 @@ pub struct Selector { } impl SelectorBase for Selector { - fn from_html(html: String) -> Self { + fn from_html>(html: S) -> Self { Selector { - text: html.to_string(), + text: html.as_ref().to_string(), } } diff --git a/tests/unit_tests.rs b/tests/unit_tests.rs index 605cc1a..f4a98e7 100644 --- a/tests/unit_tests.rs +++ b/tests/unit_tests.rs @@ -15,8 +15,7 @@ fn plain_text_selector() { simple text -" - .to_string(); +"; let sel = Selector::from_html(html); assert_eq!(sel.css("h1")[0].html(), "

hello world

"); assert_eq!(sel.css("#text")[0].content(), "good bye"); @@ -50,8 +49,7 @@ fn complex_selectors() { -" - .to_string(); +"; let sel = Selector::from_html(html); assert_eq!(sel.css_once("p").unwrap().attr("id").unwrap(), "text"); assert_eq!(sel.css("a")[0].attr("href").unwrap(), "http://google.com"); @@ -86,8 +84,7 @@ fn xpath_test() { -" - .to_string(); +"; let sel = Selector::from_html(html); assert_eq!( sel.xpath_once("//div/a[1]").unwrap().content(),