Skip to content

Rust Guide: incorrect explanation of Result.ok() / Option.expect() #17676

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

Closed
tcard opened this issue Oct 1, 2014 · 1 comment
Closed

Rust Guide: incorrect explanation of Result.ok() / Option.expect() #17676

tcard opened this issue Oct 1, 2014 · 1 comment

Comments

@tcard
Copy link
Contributor

tcard commented Oct 1, 2014

Rust provides a method on these IoResults called ok(), which does the same thing as our match statement, but assuming that we have a valid value. If we don't, it will terminate our program. In this case, if we can't get input, our program doesn't work, so we're okay with that. In most cases, we would want to handle the error case explicitly. The result of ok() has a method, expect(), which allows us to give an error message if this crash happens.

If I'm not mistaken, ok() just turns the IoResult into an Option. It won't terminate the program. It's expect() which fails or unwraps the value.

Also, wouldn't a call to the IoResult's unwrap() be more direct? Although the custom failure message would be lost.

@huonw huonw added the A-docs label Oct 1, 2014
@steveklabnik
Copy link
Member

I thought this was already fixed :/

lnicola pushed a commit to lnicola/rust that referenced this issue Jul 28, 2024
feat: add preliminary support for `+ use<..>` `precise_capturing` syntax

## Summary

This PR adds basic support for the following syntax.

```rs
fn captures<'a: 'a, 'b: 'b, T>() -> impl Sized + use<'b, T> {}
//                                  ~~~~~~~~~~~~~~~~~~~~~~~
//                          This opaque type does not capture `'a`.

fn outlives<'o, T: 'o>(_: T) {}

fn caller<'o, 'a, 'b: 'o, T: 'o>() {
    //        ~~
    //        ^ Note that we don't need `'a: 'o`.
    outlives::<'o>(captures::<'a, 'b, T>());
}
```

Related to rust-lang#17598
RalfJung pushed a commit to RalfJung/rust that referenced this issue Aug 1, 2024
feat: add preliminary support for `+ use<..>` `precise_capturing` syntax

## Summary

This PR adds basic support for the following syntax.

```rs
fn captures<'a: 'a, 'b: 'b, T>() -> impl Sized + use<'b, T> {}
//                                  ~~~~~~~~~~~~~~~~~~~~~~~
//                          This opaque type does not capture `'a`.

fn outlives<'o, T: 'o>(_: T) {}

fn caller<'o, 'a, 'b: 'o, T: 'o>() {
    //        ~~
    //        ^ Note that we don't need `'a: 'o`.
    outlives::<'o>(captures::<'a, 'b, T>());
}
```

Related to rust-lang#17598
RalfJung pushed a commit to RalfJung/rust that referenced this issue Aug 1, 2024
feat: add preliminary support for `+ use<..>` `precise_capturing` syntax

## Summary

This PR adds basic support for the following syntax.

```rs
fn captures<'a: 'a, 'b: 'b, T>() -> impl Sized + use<'b, T> {}
//                                  ~~~~~~~~~~~~~~~~~~~~~~~
//                          This opaque type does not capture `'a`.

fn outlives<'o, T: 'o>(_: T) {}

fn caller<'o, 'a, 'b: 'o, T: 'o>() {
    //        ~~
    //        ^ Note that we don't need `'a: 'o`.
    outlives::<'o>(captures::<'a, 'b, T>());
}
```

Related to rust-lang#17598
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

No branches or pull requests

3 participants