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.
-
-
Show this thread
-
What I really want is for the lifetime to be passed from the closure while the borrow holds. But blocks force a `Drop` which means the original value is gone. I don't know what the right solution is. Would love to hear if someone has a good idea on how to tackle this.
Show this thread
End of conversation
New conversation -
-
-
Use a Cow :( would be great if we could promote that lifetime of the None branch since it’s all in the same stack frame
-
Ohh, thanks! I'll give that a shot! - Have never used Cow before, so that's a fun excuse to actually try it :D Partly sad this isn't a better experience yet, but also a bit relieved I didn't miss something obvious haha.
- 4 more replies
New conversation -
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.