use std::mem;
pub trait Compact: Sized + Clone {
fn is_still_compact(&self) -> bool;
fn dynamic_size_bytes(&self) -> usize;
fn total_size_bytes(&self) -> usize {
self.dynamic_size_bytes() + mem::size_of::<Self>()
}
unsafe fn compact(source: *mut Self, dest: *mut Self, new_dynamic_part: *mut u8);
unsafe fn behind(ptr: *mut Self) -> *mut u8 {
ptr.offset(1) as *mut u8
}
unsafe fn compact_behind(source: *mut Self, dest: *mut Self) {
let behind_dest = Self::behind(dest);
Self::compact(source, dest, behind_dest)
}
unsafe fn decompact(source: *const Self) -> Self;
}
impl<T: Copy> Compact for T {
default fn is_still_compact(&self) -> bool {
true
}
default fn dynamic_size_bytes(&self) -> usize {
0
}
default unsafe fn compact(source: *mut Self, dest: *mut Self, _new_dynamic_part: *mut u8) {
*dest = *source
}
default unsafe fn decompact(source: *const Self) -> Self {
*source
}
}