Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Early exit code would be easier to write if Rust supported guard let.


its coming soon, already available on nightly.

   let Some(x) = foo() else { return 42 };


I'd suggest that something like that is already achievable by having foo return an Option and combining it with unwrap_or.


Like this?

    if let Ok(x) = my_func() {
        // ...
    }
Or do you mean something else?




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: