//! Strongly typed safe opaque pointers to GHOST handles. //! //! We define opaque ZST structures for each handle type, these then implement the [`GhostHandle`] trait, which allows them to be used for type arguments to [`Handle`](Handle). use super::*; pub use types::{Handle,GhostHandle}; pub(crate) trait AsHandle { fn as_handle(&mut self) -> &mut Handle; #[inline] fn as_raw(&mut self) -> *mut Handle { self.as_handle() as *mut Handle } } impl AsHandle for Handle { #[inline] fn as_handle(&mut self) -> &mut Handle { self } } #[cfg(not(nightly))] enum HandleInner{} macro_rules! handle { ($name:ident, $inner_name:ident) => { #[cfg(nightly)] pub struct $inner_name(!); #[cfg(not(nightly))] pub struct $inner_name(HandleInner); impl private::Sealed for $inner_name{} impl GhostHandle for $inner_name{} pub type $name = *mut Handle<$inner_name>; }; } handle!(GHOST_SystemHandle, System); handle!(GHOST_TimerTaskHandle, TimerTask); handle!(GHOST_WindowHandle, Window); handle!(GHOST_EventHandle, Event); handle!(GHOST_RectangleHandle, Rectangle); handle!(GHOST_EventConsumerHandle, EventConsumer); handle!(GHOST_ContextHandle, Context); handle!(GHOST_XrContextHandle, XrContextHandle); // This is very unsafe. /*#[inline] pub(crate) unsafe fn coerce<'a, T>(from: *mut Handle) -> &'a mut Handle where T: GhostHandle { std::mem::transmute::<*mut _, &'a mut _>(from) //this is needed because we can't safely dereference `Handle`. }*/