Skip to navigation
Questionmark in rust
25.11.25
To use the question mark in rust, you need to structure your function this way ``` fn main() -> Result<(), Error> { Ok(()) } ``` The ? replace the is_ok return check The ? placed after a Result value is defined to work in almost the same way as the match expressions we defined to handle the Result values in Listing 9-6. If the value of the Result is an Ok, the value inside the Ok will get returned from this expression, and the program will continue. If the value is an Err, the Err will be returned from the whole function as if we had used the return keyword so the error value gets propagated to the calling code.
https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html
Reply
Anonymous
Information Epoch 1780089058
Data dominates.
Home
Notebook
Contact us