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()) } } #[allow(clippy::incorrect_clone_impl_on_copy_type)] impl Clone for ConstPointer { fn clone(&self) -> Self { Self(self.0) } } impl Copy for ConstPointer {} impl Deref for ConstPointer { type Target = T; fn deref(&self) -> &Self::Target { assert!(!self.0.is_null()); unsafe { &*self.0 } } }