Think I just ran into a wart in Rust. Luckily I've got the time and enough experience at this point to know I'll be able to solve this, but others might not. Basically it's this: let foo = match bar { Some(bar) => bar, None => &make_bar()?, } where `bar` is borrowed.
-
Show this thread
-
Here's a reasonably long thread on a similiar situation from 2015: https://users.rust-lang.org/t/really-basic-lifetimes-in-match/2040 …. Using `.unwrap_or()` seems okay, but like takes 5 lines and has overhead. `unwrap_or_else()` doesn't work with error handling :( Could also use a closure inside both branches, but yuk.
2 replies 0 retweets 0 likesShow this thread -
Replying to @yoshuawuyts
I've recently run into something like this but didn't notice until CI failed -- because nightly includes some features to make pattern matching more ergonomic!
1 reply 0 retweets 2 likes -
Replying to @killercup
Ohh, which features would that be? Would be cool to read up; we're barely using any unstable features so it might be worth it here!
1 reply 0 retweets 0 likes -
Replying to @yoshuawuyts
i think it was https://github.com/rust-lang/rfcs/blob/05b989a3c614bddf97f058a93b77e4bf3b02ba5e/text/2005-match-ergonomics.md …
1 reply 0 retweets 1 like
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.