mirror of
https://github.com/rust-lang-nursery/rust-cookbook
synced 2024-11-24 20:43:07 +00:00
Add Error to Result added note for tokio
Added error to Result for main, otherwise it won't compile. If tokio isn't added with features = ["full"] main won't work, so I thought it would be a good idea to remind them.
This commit is contained in:
parent
752b035c1a
commit
2917aa9e17
1 changed files with 3 additions and 1 deletions
|
@ -37,6 +37,8 @@ fn main() -> Result<()> {
|
|||
|
||||
A similar approach can be used by including the [`tokio`] executor
|
||||
to make the main function asynchronous, retrieving the same information.
|
||||
Make sure to add tokio = {version = "1.21.2", features = ["full"]} to
|
||||
your cargo.toml file.
|
||||
|
||||
In this example, [`tokio::main`] handles all the heavy executor setup
|
||||
and allows sequential code implemented without blocking until `.await`.
|
||||
|
@ -55,7 +57,7 @@ error_chain! {
|
|||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let res = reqwest::get("http://httpbin.org/get").await?;
|
||||
println!("Status: {}", res.status());
|
||||
println!("Headers:\n{:#?}", res.headers());
|
||||
|
|
Loading…
Reference in a new issue