From eb524847408497f4ca45abf8469abe379cdfc600 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Mon, 26 Feb 2018 21:22:35 -0500 Subject: [PATCH] Remove boxes now that rust-lang/rust#38528 is fixed --- Cargo.toml | 2 +- src/lib.rs | 184 ++++++++++++++++++++++++----------------------------- 2 files changed, 84 insertions(+), 102 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 475b7ff..d9567f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fantoccini" -version = "0.8.0" +version = "0.8.1" description = "High-level API for programmatically interacting with web pages through WebDriver." readme = "README.md" diff --git a/src/lib.rs b/src/lib.rs index 9390ef9..3739541 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -450,7 +450,7 @@ impl Client { } }); - future::Either::A(Box::new(f) as Box>) + future::Either::A(f) } fn dup(&self) -> Self { @@ -771,16 +771,14 @@ impl Client { /// Navigate directly to the given URL. pub fn goto(&self, url: &str) -> impl Future + 'static { let url = url.to_owned(); - Box::new( - self.current_url_() - .and_then(move |(this, base)| Ok((this, base.join(&url)?))) - .and_then(move |(this, url)| { - this.issue_wd_cmd(WebDriverCommand::Get(webdriver::command::GetParameters { - url: url.into_string(), - })) - }) - .map(|(this, _)| this), - ) as Box> + self.current_url_() + .and_then(move |(this, base)| Ok((this, base.join(&url)?))) + .and_then(move |(this, url)| { + this.issue_wd_cmd(WebDriverCommand::Get(webdriver::command::GetParameters { + url: url.into_string(), + })) + }) + .map(|(this, _)| this) } fn current_url_( @@ -817,20 +815,16 @@ impl Client { /// Go back to the previous page. pub fn back(&self) -> impl Future + 'static { - Box::new( - self.dup() - .issue_wd_cmd(WebDriverCommand::GoBack) - .map(|(this, _)| this), - ) as Box> + self.dup() + .issue_wd_cmd(WebDriverCommand::GoBack) + .map(|(this, _)| this) } /// Refresh the current previous page. pub fn refresh(&self) -> impl Future + 'static { - Box::new( - self.dup() - .issue_wd_cmd(WebDriverCommand::Refresh) - .map(|(this, _)| this), - ) as Box> + self.dup() + .issue_wd_cmd(WebDriverCommand::Refresh) + .map(|(this, _)| this) } /// Execute the given JavaScript `script` in the current browser session. @@ -1070,14 +1064,12 @@ impl Client { &self, search: Locator, ) -> impl Future + 'static { - Box::new( - self.dup() - .issue_wd_cmd(WebDriverCommand::FindElement(search.into())) - .and_then(|(this, res)| { - let f = this.parse_lookup(res); - f.map(move |f| Form { c: this, f: f }) - }), - ) as Box> + self.dup() + .issue_wd_cmd(WebDriverCommand::FindElement(search.into())) + .and_then(|(this, res)| { + let f = this.parse_lookup(res); + f.map(move |f| Form { c: this, f: f }) + }) } // helpers @@ -1086,14 +1078,12 @@ impl Client { &self, locator: webdriver::command::LocatorParameters, ) -> impl Future + 'static { - Box::new( - self.dup() - .issue_wd_cmd(WebDriverCommand::FindElement(locator)) - .and_then(|(this, res)| { - let e = this.parse_lookup(res); - e.map(move |e| Element { c: this, e: e }) - }), - ) as Box> + self.dup() + .issue_wd_cmd(WebDriverCommand::FindElement(locator)) + .and_then(|(this, res)| { + let e = this.parse_lookup(res); + e.map(move |e| Element { c: this, e: e }) + }) } /// Extract the `WebElement` from a `FindElement` or `FindElementElement` command. @@ -1226,26 +1216,24 @@ impl Element { /// Note that since this *may* result in navigation, we give up the handle to the element. pub fn follow(self) -> impl Future + 'static { let cmd = WebDriverCommand::GetElementAttribute(self.e, "href".to_string()); - Box::new( - self.c - .issue_wd_cmd(cmd) - .and_then(|(this, href)| match href { - Json::String(v) => Ok((this, v)), - Json::Null => { - let e = WebDriverError::new( - webdriver::error::ErrorStatus::InvalidArgument, - "cannot follow element without href attribute", - ); - Err(error::CmdError::Standard(e)) - } - v => Err(error::CmdError::NotW3C(v)), - }) - .and_then(|(this, href)| { - this.current_url_() - .and_then(move |(this, url)| Ok((this, url.join(&href)?))) - }) - .and_then(|(this, href)| this.goto(href.as_str()).map(|this| this)), - ) as Box> + self.c + .issue_wd_cmd(cmd) + .and_then(|(this, href)| match href { + Json::String(v) => Ok((this, v)), + Json::Null => { + let e = WebDriverError::new( + webdriver::error::ErrorStatus::InvalidArgument, + "cannot follow element without href attribute", + ); + Err(error::CmdError::Standard(e)) + } + v => Err(error::CmdError::NotW3C(v)), + }) + .and_then(|(this, href)| { + this.current_url_() + .and_then(move |(this, url)| Ok((this, url.join(&href)?))) + }) + .and_then(|(this, href)| this.goto(href.as_str()).map(|this| this)) } } @@ -1311,25 +1299,23 @@ impl Form { button: Locator, ) -> impl Future + 'static { let locator = WebDriverCommand::FindElementElement(self.f, button.into()); - Box::new( - self.c - .issue_wd_cmd(locator) - .and_then(|(this, res)| { - let s = this.parse_lookup(res); - s.map(move |s| (this, s)) - }) - .and_then(move |(this, submit)| { - this.issue_wd_cmd(WebDriverCommand::ElementClick(submit)) - }) - .and_then(move |(this, res)| { - if res.is_null() || res.as_object().map(|o| o.is_empty()).unwrap_or(false) { - // geckodriver returns {} :( - Ok(this) - } else { - Err(error::CmdError::NotW3C(res)) - } - }), - ) as Box> + self.c + .issue_wd_cmd(locator) + .and_then(|(this, res)| { + let s = this.parse_lookup(res); + s.map(move |s| (this, s)) + }) + .and_then(move |(this, submit)| { + this.issue_wd_cmd(WebDriverCommand::ElementClick(submit)) + }) + .and_then(move |(this, res)| { + if res.is_null() || res.as_object().map(|o| o.is_empty()).unwrap_or(false) { + // geckodriver returns {} :( + Ok(this) + } else { + Err(error::CmdError::NotW3C(res)) + } + }) } /// Submit this form using the form submit button with the given label (case-insensitive). @@ -1345,7 +1331,7 @@ impl Form { button[type=submit][value=\"{}\" i]", escaped, escaped ); - Box::new(self.submit_with(Locator::Css(&btn))) as Box> + self.submit_with(Locator::Css(&btn)) } /// Submit this form directly, without clicking any buttons. @@ -1371,18 +1357,16 @@ impl Form { args: webdriver::common::Nullable::Value(args), }; - Box::new( - self.c - .issue_wd_cmd(WebDriverCommand::ExecuteScript(cmd)) - .and_then(move |(this, res)| { - if res.is_null() || res.as_object().map(|o| o.is_empty()).unwrap_or(false) { - // geckodriver returns {} :( - Ok(this) - } else { - Err(error::CmdError::NotW3C(res)) - } - }), - ) as Box> + self.c + .issue_wd_cmd(WebDriverCommand::ExecuteScript(cmd)) + .and_then(move |(this, res)| { + if res.is_null() || res.as_object().map(|o| o.is_empty()).unwrap_or(false) { + // geckodriver returns {} :( + Ok(this) + } else { + Err(error::CmdError::NotW3C(res)) + } + }) } /// Submit this form directly, without clicking any buttons, and with an extra field. @@ -1415,18 +1399,16 @@ impl Form { }; let f = self.f; - Box::new( - self.c - .issue_wd_cmd(WebDriverCommand::ExecuteScript(cmd)) - .and_then(move |(this, res)| { - if res.is_null() | res.as_object().map(|o| o.is_empty()).unwrap_or(false) { - // geckodriver returns {} :( - future::Either::A(Form { f: f, c: this }.submit_direct()) - } else { - future::Either::B(future::err(error::CmdError::NotW3C(res))) - } - }), - ) as Box> + self.c + .issue_wd_cmd(WebDriverCommand::ExecuteScript(cmd)) + .and_then(move |(this, res)| { + if res.is_null() | res.as_object().map(|o| o.is_empty()).unwrap_or(false) { + // geckodriver returns {} :( + future::Either::A(Form { f: f, c: this }.submit_direct()) + } else { + future::Either::B(future::err(error::CmdError::NotW3C(res))) + } + }) } }