|
|
|
|
|
by Arnavion
847 days ago
|
|
let p: Box<X> = Box::new(X { ... });
let x2 = X { ... };
// Moves x2 into the same memory as the first X.
// The first X is automatically dropped as part of this assignment.
// Also consumes x2 so x2 is not available any more.
*p = x2;
// Drops the X that was originally assigned to x2 and then moved into p.
drop(p);
// No need, nor is it possible, to destroy x2.
|
|
As I said I am not Rust specialist.
Also, in my understanding is that in Rust, sometimes a dynamic state is created when the object may or may not be moved.
In cake ownership this needs to me explicit ( and the destructor is not generated)
I also had a look at Rust in lifetime annotations. This concept may be necessary but I am avoiding it.
Consider this sample.
An object Y pointed by pY must live longer than object X. (Cake is not checking this scenario yet)Also (classic Rust sample)
This is not implemented yet but I want to make the lifetime of p be the smallest scope. (this is to avoid lifetime annotations)