#![allow(dead_code, unused_imports, unused_macros)]
pub type Ptr = *mut ();
macro_rules! sys {
{ @impl $($tt:tt)* } => {
#[allow(unused_imports)]
use super::*;
unsafe extern "C" { $($tt)* }
};
{ $feature:literal $($tt:tt)* } => {
cfg_select! {
feature = "unstable-sys" => {
#[cfg_attr(docsrs, doc(cfg(all(
feature = $feature,
feature = "unstable-sys"
))))]
pub mod sys {
$crate::util::sys! { @impl $($tt)* }
}
}
_ => {
mod sys {
$crate::util::sys! { @impl $($tt)* }
}
}
}
};
}
pub(crate) use sys;
macro_rules! wrapper {
{
$vis:vis struct $struct:ident;
$(new: $new:path;)?
$(
clone: $clone:path;
$(clone_from: $clone_from:path;)?
)?
drop: $drop:path;
} => {
$vis struct $struct {
__ptr: $crate::util::Ptr
}
impl $struct {
#[allow(dead_code)]
unsafe fn _new(ptr: $crate::util::Ptr) -> Self {
Self { __ptr: ptr }
}
#[allow(dead_code)]
pub(crate) fn as_ptr(&self) -> $crate::util::Ptr {
self.__ptr
}
}
$(
impl $struct {
pub fn new() -> Self {
unsafe { Self::_new($new()) }
}
}
impl Default for $struct {
fn default() -> Self {
Self::new()
}
}
)?
$(
impl Clone for $struct {
fn clone(&self) -> Self {
let ptr = unsafe { $clone(self._as_ptr()) };
unsafe { Self::_new(ptr) }
}
$(
fn clone_from(&mut self, source: &Self) {
unsafe { $clone_from(self.as_ptr(), source._as_ptr()) }
}
)?
}
)?
impl Drop for $struct {
fn drop(&mut self) {
unsafe { $drop(self.as_ptr()) }
}
}
}
}
pub(crate) use wrapper;