#[macro_export]
macro_rules! handle {
($x:expr,$y:pat) => { match $x {
$y => Err(crate::raw::um::errhandlingapi::GetLastError()),
x=> Ok(x),
}
};
($x:expr,$match_ty:ty,$y:pat,$ret_ty:ty) => { match $x as $match_ty {
$y => Err(crate::raw::um::errhandlingapi::GetLastError()),
x=> Ok(x as $ret_ty),
}
};
}
#[macro_export]
macro_rules! handle2 {
($x:expr,$err_pat:pat) => { match $x {
$err_pat => Err(crate::raw::um::errhandlingapi::GetLastError()),
_=> Ok(()),
}
};
($x:expr,$match_ty:ty,$err_pat:pat) => { match $x as $match_ty {
$err_pat => Err(crate::raw::um::errhandlingapi::GetLastError()),
_=> Ok(()),
}
};
}
#[macro_export]
macro_rules! e_handle_internal {
($x:expr,$y:pat) => { match $x {
$y => Err(()),
x=> Ok(x),
}
};
($x:expr,$match_ty:ty,$y:pat,$ret_ty:ty) => { match $x as $match_ty {
$y => Err(()),
x=> Ok(x as $ret_ty),
}
};
}
#[macro_export]
macro_rules! e_handle2_internal {
($x:expr,$err_pat:pat) => { match $x {
$err_pat => Err(()),
_=> Ok(()),
}
};
($x:expr,$match_ty:ty,$err_pat:pat) => { match $x as $match_ty {
$err_pat => Err(()),
_=> Ok(()),
}
};
}
#[macro_export]
macro_rules! make_func {
($($pa:ident)::*, $(#[$outer:meta])* pub fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) -> crate::OsResult<$ret> {
crate::handle!($($pa::)*$func($($p,)*),$err_pat)
}
);
($($pa:ident)::*, $(#[$outer:meta])* pub unsafe fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) -> crate::OsResult<$ret> {
crate::handle!($($pa::)*$func($($p,)*),$err_pat)
}
);
($($pa:ident)::*, $(#[$outer:meta])* pub safe fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub fn $func ($($p: $t,)*) -> crate::OsResult<$ret> {
unsafe { crate::handle!($($pa::)*$func($($p,)*),$err_pat) }
}
);
}
#[macro_export]
macro_rules! make_func2 {
($($pa:ident)::*, $(#[$outer:meta])* pub fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) -> crate::OsResult<()> {
crate::handle2!($($pa::)*$func($($p,)*),$err_pat)
}
);
($($pa:ident)::*, $(#[$outer:meta])* pub unsafe fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) -> crate::OsResult<()> {
crate::handle2!($($pa::)*$func($($p,)*),$err_pat)
}
);
($($pa:ident)::*, $(#[$outer:meta])* pub safe fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub fn $func ($($p: $t,)*) -> crate::OsResult<()> {
unsafe { handle2!($($pa::)*$func($($p,)*),$err_pat) }
}
);
}
#[macro_export]
macro_rules! tp_func {
($($pa:ident)::*, $(#[$outer:meta])* pub fn $func:ident($($p:ident: $t:ty,)*) $(-> $ret:ty)?$(;)?) => (
#[allow(non_snake_case)]
#[inline]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) $(-> $ret)? { $($pa::)*$func($($p,)*) }
);
($($pa:ident)::*, $(#[$outer:meta])* pub unsafe fn $func:ident($($p:ident: $t:ty,)*) $(-> $ret:ty)?$(;)?) => (
#[allow(non_snake_case)]
#[inline]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) $(-> $ret)? { $($pa::)*$func($($p,)*) }
);
($($pa:ident)::*, $(#[$outer:meta])* pub safe fn $func:ident($($p:ident: $t:ty,)*) $(-> $ret:ty)?$(;)?) => (
#[allow(non_snake_case)]
#[inline]
$(#[$outer])*
pub fn $func ($($p: $t,)*) $(-> $ret)? { unsafe {$($pa::)*$func($($p,)*)} }
);
}
#[macro_export]
macro_rules! make_struct {
($c_type: ty,
$(#[$outer:meta])*
$sv:vis struct $name:ident $(<$($attr:tt),+>)? {
$(
$(#[$inner:ident $($args:tt)*])*
$vis:vis $v:ident : $t:ty,
)*
}) => (
#[repr(C)]
$(#[$outer])*
$sv struct $name $(<$($attr),+>)?{
$(
$(#[$inner $($args)*])*
$vis $v: $t,
)*
}
impl$(<$($attr),+>)? $name $(<$($attr),+>)?{
pub fn as_ptr(&self) -> *const Self{
self as *const _
}
pub fn as_mut_ptr(&mut self) -> *mut Self{
self as *mut _
}
pub fn as_c_ptr(&self) -> *const $c_type {
self.as_ptr() as *const _
}
pub fn as_mut_c_ptr(&mut self) -> *mut $c_type {
self.as_mut_ptr() as *mut _
}
}
)
}
#[macro_export]
macro_rules! e_make_func {
($($pa:ident)::*, $(#[$outer:meta])* pub fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) -> Result<$ret, ()> {
crate::e_handle_internal!($($pa::)*$func($($p,)*),$err_pat)
}
);
($($pa:ident)::*, $(#[$outer:meta])* pub unsafe fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) -> Result<$ret, ()> {
crate::e_handle_internal!($($pa::)*$func($($p,)*),$err_pat)
}
);
($($pa:ident)::*, $(#[$outer:meta])* pub safe fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub fn $func ($($p: $t,)*) -> Result<$ret, ()> {
unsafe { crate::e_handle_internal!($($pa::)*$func($($p,)*),$err_pat) }
}
);
}
#[macro_export]
macro_rules! e_make_func2 {
($($pa:ident)::*, $(#[$outer:meta])* pub fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) -> Result<(), ()> {
crate::e_handle2_internal!($($pa::)*$func($($p,)*),$err_pat)
}
);
($($pa:ident)::*, $(#[$outer:meta])* pub unsafe fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub unsafe fn $func ($($p: $t,)*) -> Result<(), ()> {
crate::e_handle2_internal!($($pa::)*$func($($p,)*),$err_pat)
}
);
($($pa:ident)::*, $(#[$outer:meta])* pub safe fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;$err_pat:pat$(,)?) => (
#[allow(non_snake_case)]
$(#[$outer])*
pub fn $func ($($p: $t,)*) -> Result<(), ()> {
unsafe { e_handle2_internal!($($pa::)*$func($($p,)*),$err_pat) }
}
);
}
#[macro_export]
macro_rules! make_func_hresult {
($($pa:ident)::*, pub $(unsafe)? fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;) => (
#[allow(non_snake_case)]
pub unsafe fn $func ($($p: $t,)*) -> crate::OsResult<()> {
match $($pa::)*$func($($p,)*) as i32 {
winapi::shared::winerror::S_OK => Ok(()),
x => Err(x as u32),
}
}
);
($($pa:ident)::*, pub safe fn $func:ident($($p:ident: $t:ty,)*) -> $ret:ty;) => (
#[allow(non_snake_case)]
pub fn $func ($($p: $t,)*) -> crate::OsResult<()> {
unsafe {
match $($pa::)*$func($($p,)*) as i32 {
winapi::shared::winerror::S_OK => Ok(()),
x => Err(x as u32),
}
}
}
);
}