pub(crate) use owned::{OwnedProxyRegistry, destruction::ProxyDataDestruction};
use {
crate::{
ffi::wl_proxy,
proxy::{BorrowedProxy, OwnedProxy, get_owned},
},
std::{
mem::{self, ManuallyDrop},
ptr::NonNull,
},
};
pub use {
borrowed::{UntypedBorrowedProxy, UntypedBorrowedProxyWrapper},
owned::{EventHandler, UntypedOwnedProxy, UntypedOwnedProxyWrapper},
};
pub(super) mod borrowed;
pub(crate) mod owned;
#[cfg(test)]
mod tests;
pub trait CreateEventHandler<T> {
type EventHandler: EventHandler;
fn create_event_handler(handler: T) -> Self::EventHandler;
}
#[inline]
pub(crate) fn check_dispatching_proxy(proxy: Option<NonNull<wl_proxy>>) -> NonNull<wl_proxy> {
match proxy {
None => {
#[cold]
fn not_null() -> ! {
panic!("Proxy has already been destroyed");
}
not_null();
}
Some(p) => p,
}
}
#[inline]
pub(crate) fn check_new_proxy(proxy: *mut wl_proxy) -> NonNull<wl_proxy> {
if let Some(proxy) = NonNull::new(proxy) {
proxy
} else {
#[cold]
fn not_null() -> ! {
panic!("new wl_proxy is null");
}
not_null();
}
}
pub fn deref<P>(proxy: &P) -> &P::Borrowed
where
P: OwnedProxy,
{
let borrowed: &UntypedBorrowedProxy = get_owned(proxy);
unsafe { from_untyped_borrowed(borrowed) }
}
#[inline]
pub unsafe fn from_untyped_borrowed<P>(proxy: &UntypedBorrowedProxy) -> &P
where
P: BorrowedProxy,
{
unsafe { mem::transmute::<&UntypedBorrowedProxy, &P>(proxy) }
}
#[inline]
pub unsafe fn from_untyped_owned<P>(proxy: UntypedOwnedProxy) -> P
where
P: OwnedProxy,
{
let proxy = ManuallyDrop::new(proxy);
unsafe { mem::transmute_copy::<UntypedOwnedProxy, P>(&*proxy) }
}