unwrap_or_(&0) -> unwrap_or(&0)

unwrap_or_(&0) -> unwrap_or(&0)
pull/91/head
ivx 4 years ago committed by GitHub
parent 0f9b6b6a24
commit 9eb79ed6fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5902,7 +5902,7 @@ This closure takes `number_one` and `number_two`. We also gave it a new variable
Usually you see closures in Rust inside of a method, because it is very convenient to have a closure inside. We saw closures in the last section with `.map()` and `.for_each()`. In that section we wrote `|x|` to bring in the next item in an iterator, and that was a closure.
Here is another example: the `unwrap_or` method that we know that you can use to give a value if `unwrap` doesn't work. Before, we wrote: `let fourth = my_vec.get(3).unwrap_or_(&0);`. But there is also an `unwrap_or_else` method that has a closure inside. So you can do this:
Here is another example: the `unwrap_or` method that we know that you can use to give a value if `unwrap` doesn't work. Before, we wrote: `let fourth = my_vec.get(3).unwrap_or(&0);`. But there is also an `unwrap_or_else` method that has a closure inside. So you can do this:
```rust
fn main() {

Loading…
Cancel
Save