use VK_NULL_HANDLE; use std::{fmt, ops}; #[repr(C)] pub struct Handle(*mut T); impl Handle { pub fn new(value: T) -> Self { let ptr = Box::into_raw(Box::new(value)); Handle(ptr) } pub fn unwrap(self) -> Box { unsafe { Box::from_raw(self.0) } } pub fn is_null(&self) -> bool { self.0 == VK_NULL_HANDLE as *mut T } } impl Clone for Handle { fn clone(&self) -> Self { Handle(self.0) } } impl Copy for Handle {} impl ops::Deref for Handle { type Target = T; fn deref(&self) -> &T { unsafe { &*self.0 } } } impl ops::DerefMut for Handle { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.0 } } } impl fmt::Debug for Handle { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { write!(formatter, "Handle({:p})", self.0) } }