|
|
|
|
|
by nickitolas
1597 days ago
|
|
No, this is specifically not creating a mutable reference. So it's fine except for the fact that writing via assignment like this calls the destructor/drop for the old value, if the type has a Drop implementation. That's why &str is fine but String is not, since it will call Drop on a zeroed String (Which is not guaranteed to work) or on an uninitialized String. Using ptr::write instead explicitly does not Drop the old value that is being overwritten. Basically, if you have something like let v = vec![1,2,3];
v = vec![4,5,6]; // Here vec![1,2,3] is dropped otherwise we would be leaking
|
|
You mention ptr::write() but it is not used here, and I don't see how you could use it to write to a field?