# If let statement ## Example Execute the following command to run [`./solutions/examples/if_let.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/if_let/solutions/examples/if_let.rs) ```shell cargo run --example if_let ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/if_let/exercises/src/lib.rs) ### Exercise 1 ```rust pub fn unwrap_or_default(x: Option<u32>, v: u32) -> u32 { todo!(); } ``` Use the `if`, `let` syntax to extract the value stored inside a `Some`. Return the inner value. If `x` is `None`, then return the default value `v`. ## Test ```shell cargo test ```
Execute the following command to run ./solutions/examples/if_let.rs
Exercises are in ./exercises/src/lib.rs
Use the if, let syntax to extract the value stored inside a Some.
Return the inner value.
If x is None, then return the default value v.
A targeted guide to using `if let` for `Option` Handling - Learn to effectively use Rust's `if let` statement to conditionally extract values from `Option` types. You'll implement a function that returns the contained value of a `Some` or a specified default for `None`.
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on November 7, 2025
Rust Developer
Rust Programming BasicsCourse Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on November 7, 2025