Newbie missing something on value returns
⚓ Rust 📅 2026-02-28 👤 surdeus 👁️ 1I was going to try to adjust my code to get rid of some Rc<> usage. And I realized that either what I was going to do wouldn't work, or I don't understand why it would work. Two pieces:
- When returning a structured value from a method (e.g. new), the structure gets built on the stack. Does it then get copied into the callers stack space when it is returned?
- Suppose struct A { ... field: B } where B is itself a struct. and I have a method A
pub fn fill_b(mut &self, fillval: B) {
self.field = fillval;
}
does that copy fillval? Do I need to .clone() fillval explicitly? The goal is for the instance of A to be the owner of the instance of B. And the instance of A will live longer than the method that is calling fill_b. WHich suggests I will need lifetime specifiers? At which point I become uncertain as to whether iced will complain as this is in the iced update method. Which makes sure my A instance is mutable. But doesn't generally like lifetime specifiers, I think.
Yours,
Joel
1 post - 1 participant
🏷️ Rust_feed