Let's say I have this piece of Rust code:
#[derive(Debug)]
struct TestStruct<'a> {
attr: &'a str
}
impl<'a> TestStruct<'a> {
fn new() -> TestStruct<'a> {
TestStruct {
attr: "This is an test value"
}
}
}
fn main() {
let val = &mut TestStruct::new();
}
If I understand correctly, the val
contains a reference to instance of TestStruct. And if I understand correctly variable val
is not an owner of this instance, but it borrows it mutably. If so, then who's the owner of the TestStruct instance and when the lifetime of this instance ends?