4 ms·
Rust has if let. It can't chain them yet, but the proposal to fix it (RFC 2497) was accepted and implementation is in progress.
by sanxiyn 8y ago
Rust has if let. It can't chain them yet, but the proposal to fix it (RFC 2497) was accepted and implementation is in progress.
- terhechte 8y agoBut Rust lacks `guard let x = a else { return }` which is one of the nicest additions of Swift. I know there were attempts to add it to Rust, but somehow the community really doesn't like it because a `let x = match a { Some(a) => a, None => return; }` is too similar. However I feel that guard also expresses the intent.
- gamegoblin 8y agoI frequently define a `guard!` macro in Rust that does exactly that. Seems clean enough to solve at the macro level -- doesn't necessarily need to be built into the language itself.
- newacctjhro 8y agoThis kind of stuff should be on the stdlib if it's meant to be idiomatic.
- gamegoblin 8y agoRust errs on the side of not putting things in the stdlib. Even things like random number generation or regexes are not in stdlib. The excellent package manager (Cargo) makes this a non-issue.