News for hackers. Stuff that matters.
Re:SwiftWasm: Run Swift in Browsers by sanxiyn on Friday May 10, 2019 @05:13PM (#19882286)
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.
Re:SwiftWasm: Run Swift in Browsers by terhechte on Friday May 10, 2019 @05:33PM (#19882457)
But 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.
Re:SwiftWasm: Run Swift in Browsers by gamegoblin on Friday May 10, 2019 @06:13PM (#19882758)
I 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.
Re:SwiftWasm: Run Swift in Browsers by newacctjhro on Friday May 10, 2019 @07:35PM (#19883272)
This kind of stuff should be on the stdlib if it's meant to be idiomatic.
Re:SwiftWasm: Run Swift in Browsers by gamegoblin on Friday May 10, 2019 @07:58PM (#19883417)
Rust 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.