Why can't I store a value and a reference to that value in the same struct?
@lebyy▲ 0 net votes
Problem: I have a value and I want to store that value and a reference to something inside that value in my own type: struct Thing { count: u32, } struct Combined<'a>(Thing, &'a u32); fn make_combined<'a>() -> Combined& Sometimes, I have a value and I want to store… Fix (from the top answer): Let's look at a simple implementation of this : struct Parent { count: u32, } struct Child<'a> { parent: &'a Parent, } struct Combined<'a> { parent: Par This will fail with the error: error[E0515]: cannot return value referencing local variable parent --> src/main.rs:19:9 | 17 | let child = Child { To completely…