Post #2564784
2026-04-29 16:03 UTC
@Ambraven@social.mochi.academy I think this is what you're looking for: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=6a3bfd5d1f8222236c6c77d67c29d3e5
Replies (2)
-
@terts@mastodon.online 2026-04-29 16:06
@Ambraven@social.mochi.academy The trick is to declare (but not assign!) a variable in the outer scope and then only assign to it in the else branch. That ensures that you can give out a reference with the lifetime of the function.
-
@Ambraven@social.mochi.academy 2026-04-29 20:41
@terts@mastodon.online Yes, that's it. Thanks. It's wordy but I don't see better way to write it.