constellation
constellation copied to clipboard
VecResource<T> must implement Drop
In its current implementation, VecResource<T> will drop all contained values when it's deleted, even the uninitialized ones. Depending on what T is, this might go unnoticed for a long time or simply crash (as in my recent case). The correct implementation should probably be something like this:
impl<T: Any + Send + Sync> Drop for VecResource<T> {
fn drop(&mut self) {
use std::mem::drop;
for i in 0..self.storage.v.len() {
if self.storage.g[i] != None {
unsafe {
drop(self.storage.v.get_unchecked_mut(i));
}
}
}
unsafe {
self.storage.v.set_len(0);
}
drop(&mut self.storage.v);
drop(&mut self.storage.g);
}
}