std-method

Result::unwrap_or_default

Extract the success value or return the type-defined default after discarding an error. Use only if the fallback is appropriate for the domain. Expected stdout (not executed): 0 Common mistake: Treating a failed payment as a zero-valued successful payment.

Formal Syntax & Structure

rust syntaxrust
fn unwrap_or_default(self) -> T where T: Default

Working Example

Example Snippetrust
fn main() {    let count = "invalid".parse::<u32>().unwrap_or_default();    println!("{count}");}
Rust Reference