I don't see why you need async in your program - all you do is hit an api once, wait for the result and print it on screen. This program should work exactly the same without async/await.
A better example would be to pass multiple company names and fetch the data concurrently.
Also I don't think the ? operator is the same as unwrap. unwrap will panic the current thread if the result an Err, while ? will propagate it to the call site.
It's true that async is not needed but I wanted to show how to use async/await in Rust.
A better example would be to pass multiple company names and fetch the data concurrently.
Great idea! I will be sure to implement that type of tutorial soon. Also, the ? operator is not the same as unwrap, you're right. Since this post is more for beginners and it wasn't focused on the ? operator, I just wanted them to be familiar with the syntax and not have to worry about what it does.
API requests should always be async. What if the network is down. Obviously a timeout and error handling would be good too, but since its a demo, just the async is fine.
They absolutely donβt have to be. It depends on the context. And in this particular example, you gain nothing by using async Rust.
The network being down and async are two unrelated concepts. Async doesnβt magically fix the network, nor it helps you deal with errors better/easier.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice writeup.
I don't see why you need async in your program - all you do is hit an api once, wait for the result and print it on screen. This program should work exactly the same without async/await.
A better example would be to pass multiple company names and fetch the data concurrently.
Also I don't think the
?operator is the same asunwrap.unwrapwill panic the current thread if the result anErr, while?will propagate it to the call site.It's true that async is not needed but I wanted to show how to use async/await in Rust.
Great idea! I will be sure to implement that type of tutorial soon. Also, the
?operator is not the same asunwrap, you're right. Since this post is more for beginners and it wasn't focused on the?operator, I just wanted them to be familiar with the syntax and not have to worry about what it does.Thanks for your input.
API requests should always be async. What if the network is down. Obviously a timeout and error handling would be good too, but since its a demo, just the async is fine.
They absolutely donβt have to be. It depends on the context. And in this particular example, you gain nothing by using async Rust.
The network being down and async are two unrelated concepts. Async doesnβt magically fix the network, nor it helps you deal with errors better/easier.