5/5
# `?` operator ## Example Execute the following command to run [`./solutions/examples/question.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/question/solutions/examples/question.rs) ```shell cargo run --example question ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/question/exercises/src/lib.rs) ### Exercise 1 ```rust pub fn sum(nums: &[&str]) -> Result<u32, String> { todo!(); } ``` Parse the slice of string slices into `u32` and return their sum. Call the `parse` function to parse a `&str` into `u32`. Use `?` to make your code shorter. ### Test ```shell cargo test ```
?
operatorExecute the following command to run ./solutions/examples/question.rs
Exercises are in ./exercises/src/lib.rs
Parse the slice of string slices into u32
and return their sum.
Call the parse
function to parse a &str
into u32
.
Use ?
to make your code shorter.
A practical dive into the `?` operator - Learn how this powerful Rust feature streamlines error handling and enhances code readability. You'll put this knowledge to use by parsing string slices into `u32`s and calculating their sum.
Previous lesson
Previous
Next lesson
Next
Give us feedback
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 September 3, 2025
Rust Developer
Rust Programming BasicsDuration: 6min
Duration: 18min
Duration: 47min
Duration: 15min
Duration: 19min
Duration: 8min
Duration: 12min
Duration: 46min
Duration: 14min
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 September 3, 2025