Skip to content

Commit 7bbf429

Browse files
committed
Make all examples use generic error.
1 parent bdd08d2 commit 7bbf429

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

examples/persistent.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use async_std::task;
22

3+
type BoxError = Box<dyn std::error::Error + Send + Sync>;
4+
35
// The need for Ok with turbofish is explained here
46
// https://rust-lang.github.io/async-book/07_workarounds/03_err_in_async_blocks.html
5-
fn main() -> Result<(), surf::Error> {
6-
femme::start(log::LevelFilter::Info).unwrap();
7+
fn main() -> Result<(), BoxError> {
8+
femme::start(log::LevelFilter::Info)?;
79
task::block_on(async {
810
let client = surf::Client::new();
911
let req1 = client.get("https://httpbin.org/get").recv_string();
1012
let req2 = client.get("https://httpbin.org/get").recv_string();
1113
futures::future::try_join(req1, req2).await?;
12-
Ok::<(), surf::Error>(())
14+
Ok(())
1315
})
1416
}

examples/post.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use async_std::task;
22

3-
// The need for Ok with turbofish is explained here
4-
// https://rust-lang.github.io/async-book/07_workarounds/03_err_in_async_blocks.html
5-
fn main() -> Result<(), surf::Error> {
6-
femme::start(log::LevelFilter::Info).unwrap();
3+
type BoxError = Box<dyn std::error::Error + Send + Sync>;
4+
5+
fn main() -> Result<(), BoxError> {
6+
femme::start(log::LevelFilter::Info)?;
77
task::block_on(async {
88
let uri = "https://httpbin.org/post";
99
let data = serde_json::json!({ "name": "chashu" });
10+
// unwrap note: we are definitely passing valid json so we should never panic.
1011
let res = surf::post(uri).body_json(&data).unwrap().await?;
1112
assert_eq!(res.status(), 200);
12-
Ok::<(), surf::Error>(())
13+
Ok(())
1314
})
1415
}

0 commit comments

Comments
 (0)