mirror of
https://github.com/lisk77/comet.git
synced 2025-12-12 17:18:50 +00:00
fix(ecs): some replacement issues
This commit is contained in:
parent
a01a52766d
commit
eced6ddf3f
8 changed files with 176 additions and 112 deletions
|
|
@ -272,6 +272,22 @@ impl Column {
|
|||
}
|
||||
}
|
||||
|
||||
/// Overwrites an existing element in place, dropping the previous value.
|
||||
pub fn set<T: 'static>(&mut self, index: usize, item: T) -> Option<()> {
|
||||
assert_eq!(TypeId::of::<T>(), TypeId::of::<T>(), "Type mismatch");
|
||||
if index >= self.data.len() {
|
||||
return None;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let ptr = self.data.get_unchecked_mut(index) as *mut T;
|
||||
ptr::drop_in_place(ptr);
|
||||
ptr::write(ptr, item);
|
||||
}
|
||||
|
||||
Some(())
|
||||
}
|
||||
|
||||
pub fn swap(&mut self, index1: usize, index2: usize) {
|
||||
assert!(
|
||||
index1 < self.data.len() && index2 < self.data.len(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue