Example:
struct Something(Thing);
impl Something {
fn run(&self) -> &Thing {
// This works (as expected)
// let thing = &self.0;
// This doesn't work. (temporary value)
// let thing = &self.0.clone();
// Then why does this work? (isn't this a temporary value?)
let thing = &Thing {};
thing
}
}
#[derive(Clone)]
struct Thing {}
I don't understand why am I allowed to create a Thing{}
and return a reference to it, but I am unable to clone and return the existing one in the struct field.