File tree 2 files changed +11
-8
lines changed
2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change 1
1
use async_std:: task;
2
2
3
+ type BoxError = Box < dyn std:: error:: Error + Send + Sync > ;
4
+
3
5
// The need for Ok with turbofish is explained here
4
6
// 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 ) ? ;
7
9
task:: block_on ( async {
8
10
let client = surf:: Client :: new ( ) ;
9
11
let req1 = client. get ( "https://httpbin.org/get" ) . recv_string ( ) ;
10
12
let req2 = client. get ( "https://httpbin.org/get" ) . recv_string ( ) ;
11
13
futures:: future:: try_join ( req1, req2) . await ?;
12
- Ok :: < ( ) , surf :: Error > ( ( ) )
14
+ Ok ( ( ) )
13
15
} )
14
16
}
Original file line number Diff line number Diff line change 1
1
use async_std:: task;
2
2
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 ) ? ;
7
7
task:: block_on ( async {
8
8
let uri = "https://httpbin.org/post" ;
9
9
let data = serde_json:: json!( { "name" : "chashu" } ) ;
10
+ // unwrap note: we are definitely passing valid json so we should never panic.
10
11
let res = surf:: post ( uri) . body_json ( & data) . unwrap ( ) . await ?;
11
12
assert_eq ! ( res. status( ) , 200 ) ;
12
- Ok :: < ( ) , surf :: Error > ( ( ) )
13
+ Ok ( ( ) )
13
14
} )
14
15
}
You can’t perform that action at this time.
0 commit comments