Skip to content

Commit d2442af

Browse files
committed
Box all chains to work around rust-lang/rust#38528
This commit should be reverted once that issue has been resolved.
1 parent 73ca215 commit d2442af

File tree

1 file changed

+96
-82
lines changed

1 file changed

+96
-82
lines changed

src/lib.rs

Lines changed: 96 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl Client {
425425
}
426426
});
427427
(
428-
future::Either::A(f),
428+
future::Either::A(Box::new(f) as Box<Future<Item = _, Error = _>>),
429429
future::Either::A(rx.into_future().then(|_| Ok(()))),
430430
)
431431
}
@@ -736,14 +736,16 @@ impl Client {
736736
/// Navigate directly to the given URL.
737737
pub fn goto(&self, url: &str) -> impl Future<Item = Self, Error = error::CmdError> + 'static {
738738
let url = url.to_owned();
739-
self.current_url_()
740-
.and_then(move |(this, base)| Ok((this, base.join(&url)?)))
741-
.and_then(move |(this, url)| {
742-
this.issue_wd_cmd(WebDriverCommand::Get(
743-
webdriver::command::GetParameters { url: url.into_string() },
744-
))
745-
})
746-
.map(|(this, _)| this)
739+
Box::new(
740+
self.current_url_()
741+
.and_then(move |(this, base)| Ok((this, base.join(&url)?)))
742+
.and_then(move |(this, url)| {
743+
this.issue_wd_cmd(WebDriverCommand::Get(webdriver::command::GetParameters {
744+
url: url.into_string(),
745+
}))
746+
})
747+
.map(|(this, _)| this),
748+
) as Box<Future<Item = _, Error = _>>
747749
}
748750

749751
#[inline]
@@ -1020,13 +1022,15 @@ impl Client {
10201022
selector: &str,
10211023
) -> impl Future<Item = Form, Error = error::CmdError> + 'static {
10221024
let locator = Self::mklocator(selector);
1023-
self.dup()
1024-
.issue_wd_cmd(WebDriverCommand::FindElement(locator))
1025-
.map_err(|e| e.into())
1026-
.and_then(|(this, res)| {
1027-
let f = this.parse_lookup(res);
1028-
f.map(move |f| Form { c: this, f: f })
1029-
})
1025+
Box::new(
1026+
self.dup()
1027+
.issue_wd_cmd(WebDriverCommand::FindElement(locator))
1028+
.map_err(|e| e.into())
1029+
.and_then(|(this, res)| {
1030+
let f = this.parse_lookup(res);
1031+
f.map(move |f| Form { c: this, f: f })
1032+
}),
1033+
) as Box<Future<Item = _, Error = _>>
10301034
}
10311035

10321036
// helpers
@@ -1036,13 +1040,15 @@ impl Client {
10361040
&self,
10371041
locator: webdriver::command::LocatorParameters,
10381042
) -> impl Future<Item = Element, Error = error::CmdError> + 'static {
1039-
self.dup()
1040-
.issue_wd_cmd(WebDriverCommand::FindElement(locator))
1041-
.map_err(|e| e.into())
1042-
.and_then(|(this, res)| {
1043-
let e = this.parse_lookup(res);
1044-
e.map(move |e| Element { c: this, e: e })
1045-
})
1043+
Box::new(
1044+
self.dup()
1045+
.issue_wd_cmd(WebDriverCommand::FindElement(locator))
1046+
.map_err(|e| e.into())
1047+
.and_then(|(this, res)| {
1048+
let e = this.parse_lookup(res);
1049+
e.map(move |e| Element { c: this, e: e })
1050+
}),
1051+
) as Box<Future<Item = _, Error = _>>
10461052
}
10471053

10481054
/// Extract the `WebElement` from a `FindElement` or `FindElementElement` command.
@@ -1187,24 +1193,26 @@ impl Element {
11871193
/// Note that since this *may* result in navigation, we give up the handle to the element.
11881194
pub fn follow(self) -> impl Future<Item = Client, Error = error::CmdError> + 'static {
11891195
let cmd = WebDriverCommand::GetElementAttribute(self.e, "href".to_string());
1190-
self.c
1191-
.issue_wd_cmd(cmd)
1192-
.and_then(|(this, href)| match href {
1193-
Json::String(v) => Ok((this, v)),
1194-
Json::Null => {
1195-
let e = WebDriverError::new(
1196-
webdriver::error::ErrorStatus::InvalidArgument,
1197-
"cannot follow element without href attribute",
1198-
);
1199-
Err(error::CmdError::Standard(e))
1200-
}
1201-
v => Err(error::CmdError::NotW3C(v)),
1202-
})
1203-
.and_then(|(this, href)| {
1204-
this.current_url_()
1205-
.and_then(move |(this, url)| Ok((this, url.join(&href)?)))
1206-
})
1207-
.and_then(|(this, href)| this.goto(href.as_str()).map(|this| this))
1196+
Box::new(
1197+
self.c
1198+
.issue_wd_cmd(cmd)
1199+
.and_then(|(this, href)| match href {
1200+
Json::String(v) => Ok((this, v)),
1201+
Json::Null => {
1202+
let e = WebDriverError::new(
1203+
webdriver::error::ErrorStatus::InvalidArgument,
1204+
"cannot follow element without href attribute",
1205+
);
1206+
Err(error::CmdError::Standard(e))
1207+
}
1208+
v => Err(error::CmdError::NotW3C(v)),
1209+
})
1210+
.and_then(|(this, href)| {
1211+
this.current_url_()
1212+
.and_then(move |(this, url)| Ok((this, url.join(&href)?)))
1213+
})
1214+
.and_then(|(this, href)| this.goto(href.as_str()).map(|this| this)),
1215+
) as Box<Future<Item = _, Error = _>>
12081216
}
12091217
}
12101218

@@ -1270,24 +1278,26 @@ impl Form {
12701278
) -> impl Future<Item = Client, Error = error::CmdError> + 'static {
12711279
let locator = Client::mklocator(button);
12721280
let locator = WebDriverCommand::FindElementElement(self.f, locator);
1273-
self.c
1274-
.issue_wd_cmd(locator)
1275-
.map_err(|e| e.into())
1276-
.and_then(|(this, res)| {
1277-
let s = this.parse_lookup(res);
1278-
s.map(move |s| (this, s))
1279-
})
1280-
.and_then(move |(this, submit)| {
1281-
this.issue_wd_cmd(WebDriverCommand::ElementClick(submit))
1282-
})
1283-
.and_then(move |(this, res)| {
1284-
if res.is_null() || res.as_object().map(|o| o.is_empty()).unwrap_or(false) {
1285-
// geckodriver returns {} :(
1286-
Ok(this)
1287-
} else {
1288-
Err(error::CmdError::NotW3C(res))
1289-
}
1290-
})
1281+
Box::new(
1282+
self.c
1283+
.issue_wd_cmd(locator)
1284+
.map_err(|e| e.into())
1285+
.and_then(|(this, res)| {
1286+
let s = this.parse_lookup(res);
1287+
s.map(move |s| (this, s))
1288+
})
1289+
.and_then(move |(this, submit)| {
1290+
this.issue_wd_cmd(WebDriverCommand::ElementClick(submit))
1291+
})
1292+
.and_then(move |(this, res)| {
1293+
if res.is_null() || res.as_object().map(|o| o.is_empty()).unwrap_or(false) {
1294+
// geckodriver returns {} :(
1295+
Ok(this)
1296+
} else {
1297+
Err(error::CmdError::NotW3C(res))
1298+
}
1299+
}),
1300+
) as Box<Future<Item = _, Error = _>>
12911301
}
12921302

12931303
/// Submit this form using the form submit button with the given label (case-insensitive).
@@ -1296,14 +1306,14 @@ impl Form {
12961306
pub fn submit_using(
12971307
self,
12981308
button_label: &str,
1299-
) -> impl Future<Item = Client, Error = error::CmdError> {
1309+
) -> impl Future<Item = Client, Error = error::CmdError> + 'static {
13001310
let escaped = button_label.replace('\\', "\\\\").replace('"', "\\\"");
1301-
self.submit_with(&format!(
1311+
Box::new(self.submit_with(&format!(
13021312
"input[type=submit][value=\"{}\" i],\
13031313
button[type=submit][value=\"{}\" i]",
13041314
escaped,
13051315
escaped
1306-
))
1316+
))) as Box<Future<Item = _, Error = _>>
13071317
}
13081318

13091319
/// Submit this form directly, without clicking any buttons.
@@ -1329,16 +1339,18 @@ impl Form {
13291339
args: webdriver::common::Nullable::Value(args),
13301340
};
13311341

1332-
self.c
1333-
.issue_wd_cmd(WebDriverCommand::ExecuteScript(cmd))
1334-
.and_then(move |(this, res)| {
1335-
if res.is_null() || res.as_object().map(|o| o.is_empty()).unwrap_or(false) {
1336-
// geckodriver returns {} :(
1337-
Ok(this)
1338-
} else {
1339-
Err(error::CmdError::NotW3C(res))
1340-
}
1341-
})
1342+
Box::new(
1343+
self.c
1344+
.issue_wd_cmd(WebDriverCommand::ExecuteScript(cmd))
1345+
.and_then(move |(this, res)| {
1346+
if res.is_null() || res.as_object().map(|o| o.is_empty()).unwrap_or(false) {
1347+
// geckodriver returns {} :(
1348+
Ok(this)
1349+
} else {
1350+
Err(error::CmdError::NotW3C(res))
1351+
}
1352+
}),
1353+
) as Box<Future<Item = _, Error = _>>
13421354
}
13431355

13441356
/// Submit this form directly, without clicking any buttons, and with an extra field.
@@ -1371,16 +1383,18 @@ impl Form {
13711383
};
13721384

13731385
let f = self.f;
1374-
self.c
1375-
.issue_wd_cmd(WebDriverCommand::ExecuteScript(cmd))
1376-
.and_then(move |(this, res)| {
1377-
if res.is_null() | res.as_object().map(|o| o.is_empty()).unwrap_or(false) {
1378-
// geckodriver returns {} :(
1379-
future::Either::A(Form { f: f, c: this }.submit_direct())
1380-
} else {
1381-
future::Either::B(future::err(error::CmdError::NotW3C(res)))
1382-
}
1383-
})
1386+
Box::new(
1387+
self.c
1388+
.issue_wd_cmd(WebDriverCommand::ExecuteScript(cmd))
1389+
.and_then(move |(this, res)| {
1390+
if res.is_null() | res.as_object().map(|o| o.is_empty()).unwrap_or(false) {
1391+
// geckodriver returns {} :(
1392+
future::Either::A(Form { f: f, c: this }.submit_direct())
1393+
} else {
1394+
future::Either::B(future::err(error::CmdError::NotW3C(res)))
1395+
}
1396+
}),
1397+
) as Box<Future<Item = _, Error = _>>
13841398
}
13851399
}
13861400

0 commit comments

Comments
 (0)