Open shubhamkumar13 opened 1 year ago
Is there any reason this requires a dependency on http_types instead of using surf::Error?
I think @jbr you are right there is no specific reason for http_types.
I didn't realise there is a surf::Error
.
So initially I was using the hello_world.rs example and I landed on using the exterior part of the main function :
#[async_std::main]
async fn main() -> Result<(), http_types::Error> {
// fill the readme stuff here
}
And fill the above function with the code mentioned in the README.md which ended up looking like this :
#[async_std::main]
async fn main() -> Result<(), http_types::Error> {
let mut res = surf::get("https://httpbin.org/get").await?;
dbg!(res.body_string().await?);
Ok(())
}
which resulted in the following error
❯ cargo run
Compiling trying_surf v0.1.0 (/home/sk/trying_surf)
error[E0433]: failed to resolve: use of undeclared crate or module `http_types`
--> src/main.rs:9:31
|
9 | async fn main() -> Result<(), http_types::Error> {
| ^^^^^^^^^^ use of undeclared crate or module `http_types`
For more information about this error, try `rustc --explain E0433`.
error: could not compile `trying_surf` due to previous error
so adding a use http_types::Error;
fixed the above statement and I went with it.
But now that you mentioned it when I change the code to :
#[async_std::main]
async fn main() -> Result<(), surf::Error> {
let mut res = surf::get("https://httpbin.org/get").await?;
dbg!(res.body_string().await?);
Ok(())
}
it looks good! and runs without any errors!!
So I'll update the PR and if it's ok can you approve it? Thanks for the pointer :smiley:
is it ok if I update the examples directory it can be a bit confusing for beginners?
So this might be a very small change but I was confused how to use the previous version of this example.
This change makes the example plug and play and easier for beginners like me to use it.
Would love to have an opinion on this :smiley: