Skip to content

Commit

Permalink
Remove boxes now that rust-lang/rust#38528 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Feb 27, 2018
1 parent 5e52fc5 commit eb52484
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
184 changes: 83 additions & 101 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ impl Client {
}
});

future::Either::A(Box::new(f) as Box<Future<Item = _, Error = _>>)
future::Either::A(f)
}

fn dup(&self) -> Self {
Expand Down Expand Up @@ -771,16 +771,14 @@ impl Client {
/// Navigate directly to the given URL.
pub fn goto(&self, url: &str) -> impl Future<Item = Self, Error = error::CmdError> + '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<Future<Item = _, Error = _>>
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_(
Expand Down Expand Up @@ -817,20 +815,16 @@ impl Client {

/// Go back to the previous page.
pub fn back(&self) -> impl Future<Item = Self, Error = error::CmdError> + 'static {
Box::new(
self.dup()
.issue_wd_cmd(WebDriverCommand::GoBack)
.map(|(this, _)| this),
) as Box<Future<Item = _, Error = _>>
self.dup()
.issue_wd_cmd(WebDriverCommand::GoBack)
.map(|(this, _)| this)
}

/// Refresh the current previous page.
pub fn refresh(&self) -> impl Future<Item = Self, Error = error::CmdError> + 'static {
Box::new(
self.dup()
.issue_wd_cmd(WebDriverCommand::Refresh)
.map(|(this, _)| this),
) as Box<Future<Item = _, Error = _>>
self.dup()
.issue_wd_cmd(WebDriverCommand::Refresh)
.map(|(this, _)| this)
}

/// Execute the given JavaScript `script` in the current browser session.
Expand Down Expand Up @@ -1070,14 +1064,12 @@ impl Client {
&self,
search: Locator,
) -> impl Future<Item = Form, Error = error::CmdError> + '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<Future<Item = _, Error = _>>
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
Expand All @@ -1086,14 +1078,12 @@ impl Client {
&self,
locator: webdriver::command::LocatorParameters,
) -> impl Future<Item = Element, Error = error::CmdError> + '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<Future<Item = _, Error = _>>
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.
Expand Down Expand Up @@ -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<Item = Client, Error = error::CmdError> + '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<Future<Item = _, Error = _>>
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))
}
}

Expand Down Expand Up @@ -1311,25 +1299,23 @@ impl Form {
button: Locator,
) -> impl Future<Item = Client, Error = error::CmdError> + '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<Future<Item = _, Error = _>>
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).
Expand All @@ -1345,7 +1331,7 @@ impl Form {
button[type=submit][value=\"{}\" i]",
escaped, escaped
);
Box::new(self.submit_with(Locator::Css(&btn))) as Box<Future<Item = _, Error = _>>
self.submit_with(Locator::Css(&btn))
}

/// Submit this form directly, without clicking any buttons.
Expand All @@ -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<Future<Item = _, Error = _>>
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.
Expand Down Expand Up @@ -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<Future<Item = _, Error = _>>
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)))
}
})
}
}

Expand Down

0 comments on commit eb52484

Please sign in to comment.