Post #2564775
2026-04-29 15:15 UTC
@Ambraven@social.mochi.academy depending on what you want to achieve you have different options. If A implements default you can use unwrap_or_default().
You can first clone foo, as you are cloning inside anyway.
Having a ref in an option is pretty common, so you should force yourself into cloning / rc'ing.
Replies (1)
-
@mohs@climatejustice.social 2026-04-29 15:36
@Ambraven@social.mochi.academy the others mention a good path, but there is also map_or for this approach. e.g: foo.map_or(A::new(), A::clone);