#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), forbid(unsafe_code))]
#[cfg(feature = "std")]
mod str;
#[cfg(feature = "std")]
mod vec;
#[cfg(feature = "std")]
pub use self::{str::*, vec::*};
pub trait ReprC<T>: private::CFFISafe {
fn from(_: T) -> Self;
}
pub trait ReprRust<T: private::CFFISafe> {
fn from(_: T) -> Self;
}
mod private {
pub trait CFFISafe {}
macro_rules! c_ffi_safe {
($($ty:ty),*) => {$(
impl CFFISafe for $ty {}
impl CFFISafe for *const $ty {}
)*};
}
c_ffi_safe![(), i8, i16, i32, i64, u8, u16, u32, u64, f32, f64];
}
macro_rules! transparent {
($($ty:ty),*) => {$(
impl ReprRust<$ty> for $ty {
#[inline]
fn from(x: $ty) -> Self { x }
}
impl ReprC<$ty> for $ty {
#[inline]
fn from(x: $ty) -> Self { x }
}
impl ReprRust<*const $ty> for *const $ty {
#[inline]
fn from(x: *const $ty) -> Self { x }
}
impl ReprC<*const $ty> for *const $ty {
#[inline]
fn from(x: *const $ty) -> Self { x }
}
)*};
}
transparent![i8, i16, i32, i64, u8, u16, u32, u64, f32, f64];
impl ReprC<()> for () {
#[inline]
fn from(_: ()) -> Self {}
}
impl<T> ReprRust<*const T> for *mut T
where
*const T: private::CFFISafe,
{
fn from(x: *const T) -> Self {
x as *mut T
}
}