use std::{ fmt::Debug, ops::{Deref, DerefMut}, }; pub mod logset; pub mod mm; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct ObjectWrapper { object: Box, } impl ObjectWrapper { pub fn new(buf: &[u8]) -> Option { if buf.len() != std::mem::size_of::() { println!( "ObjectWrapper::new(): buf.len() '{}' != std::mem::size_of::(): '{}'", buf.len(), std::mem::size_of::() ); return None; } let x = unsafe { std::ptr::read(buf.as_ptr() as *const T) }; let object = Box::new(x); // let object = ManuallyDrop::new(x); Some(Self { object }) } } impl DerefMut for ObjectWrapper { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.object } } impl Deref for ObjectWrapper { type Target = T; fn deref(&self) -> &Self::Target { &self.object } }