use std::ops::Deref; /// Raw pointer that implements Default. /// Additionally it implements Deref so it's more ergonomic than Option. #[derive(Debug)] pub struct ConstPointer(pub *const T); impl From<&T> for ConstPointer { fn from(value: &T) -> Self { Self(value) } } impl Default for ConstPointer { fn default() -> Self { Self(std::ptr::null()) } } impl Clone for ConstPointer { fn clone(&self) -> Self { *self } } impl Copy for ConstPointer {} impl Deref for ConstPointer { type Target = T; fn deref(&self) -> &Self::Target { assert!(!self.0.is_null()); unsafe { &*self.0 } } }