Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README example #349

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shubhamkumar13
Copy link

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 😃

@jbr
Copy link
Member

jbr commented Aug 11, 2022

Is there any reason this requires a dependency on http_types instead of using surf::Error?

@shubhamkumar13
Copy link
Author

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 😃

@shubhamkumar13
Copy link
Author

is it ok if I update the examples directory it can be a bit confusing for beginners?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants