use crate::ffi::wl_proxy;
use crate::proxy::BorrowedProxy;
use crate::proxy::OwnedProxy;
use crate::proxy::get_owned;
pub use borrowed::UntypedBorrowedProxy;
pub use borrowed::UntypedBorrowedProxyWrapper;
pub use owned::EventHandler;
pub(crate) use owned::OwnedProxyRegistry;
pub use owned::UntypedOwnedProxy;
pub use owned::UntypedOwnedProxyWrapper;
pub(crate) use owned::destruction::ProxyDataDestruction;
use std::mem;
use std::mem::ManuallyDrop;
use std::ptr::NonNull;
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) }
}