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
Examples with ?
operator not working?
#275
Comments
try: extern crate reqwest;
fn foo() -> Result<(), reqwest::Error> {
let text = reqwest::get("https://www.rust-lang.org")?
.text()?;
println!("body = {:?}", text);
Ok(())
}
fn main() {
foo().unwrap();
} |
Thanks @messense that works & confirms my guess that it only works within a function returning a |
The examples were changed to show using In the meantime, this might be helpful: have the very first example show using in |
I dug into this a bit and indeed found it is the recommended way to write examples. I'm fond of copy and pasting snippets to try but I can see how this provides a cleaner way of showing functionality. Guess most people won't get as confused as I was about the Will create a PR! |
Clarify code example structure in combination with the `?` operator. Add as separate section so it can be easily removed when `?` can be used inside of `main`. Closes #275
seems that even without a function is now supported. extern crate reqwest;
fn main() -> reqwest::Result<()> {
let body = reqwest::get("https://www.rust-lang.org")?.text()?;
println!("{}", body);
Ok(())
} tested on |
None of the above examples work on Rust 1.40....... |
same here |
Confirmed. It does not work on 1.4.3 either. |
same problem here. |
Hi there, I'm new to Rust so this might not be related to
reqwest
. As far as I understand the?
operator can only be used inside functions that return aResult
. However in the examples this isn't mentioned. Simply running the first example:Returns
cannot use the ? operator in a function that returns ()
andbody not found in this scope
. Then changing the code to:Returns
no method named text found for type std::result::Result<reqwest::Response, reqwest::Error>
, any help appreciated.The text was updated successfully, but these errors were encountered: