mod hs;
mod str;
pub use self::{hs::HsType, str::*};
use core::ffi::*;
pub trait ReprC<T>: private::CFFISafe {
fn from(_: T) -> Self;
}
pub trait ReprRust<T: private::CFFISafe> {
fn from(_: T) -> Self;
}
mod private {
use core::ffi::*;
pub trait CFFISafe {}
macro_rules! c_ffi_safe {
($($ty:ty),*) => {$(
impl CFFISafe for $ty {}
)*};
}
c_ffi_safe![
(),
*const c_char,
c_char,
c_double,
c_float,
c_int,
c_long,
c_short,
c_uchar,
c_uint,
c_ulong,
c_ushort
];
}
macro_rules! transparent {
($($ty:ty),*) => {$(
impl ReprRust<$ty> for $ty {
fn from(x: $ty) -> Self { x }
}
impl ReprC<$ty> for $ty {
fn from(x: $ty) -> Self { x }
}
)*};
}
transparent![
(),
*const c_char,
c_char,
c_double,
c_float,
c_int,
c_long,
c_short,
c_uchar,
c_uint,
c_ulong,
c_ushort
];
pub trait ReprHs {
fn into() -> HsType;
}
macro_rules! repr_hs {
($($ty:ty => $ident:ident,)*) => {$(
impl ReprHs for $ty {
fn into() -> HsType {
HsType::$ident
}
}
)*};
}
pub(crate) use repr_hs;
repr_hs! {
c_char => CChar,
c_double => CDouble,
c_float => CFloat,
c_int => CInt,
c_long => CLong,
c_short => CShort,
c_uchar => CUChar,
c_uint => CUInt,
c_ulong => CULong,
c_ushort => CUShort,
}