News for hackers. Stuff that matters.
Re:Effective Rust by laeri on Thursday June 15, 2023 @08:38AM (#36339614)
Can you also use `unwrap_or_default` in this example?
Re:Effective Rust by Omin on Thursday June 15, 2023 @09:24AM (#36340105)
No, because it requires an &Vec<_> and that doesn't implement Default and for good reason. Just ask yourself, where would the default empty vec live so that you could create a reference to it.

When using unwrap_or(&vec![]), it lives in the enclosing stack. Without the reference, you could use unwrap_or_default().

Re:Effective Rust by laeri on Thursday June 15, 2023 @09:27AM (#36340153)
Thanks for your reply that cleared it up. Was a bit confused why the `unwrap_or(&vec![])` worked but as you said it lives in the enclosing stack.