binding/src/c_types.rs

93 lines
2.2 KiB
Rust
Raw Normal View History

//! This defines the primitive types that may be seen
//! when creating 'C' bindings.
//!
//! There are several places where the target architecture and the OS
//! require special consideration. These are handled
//! with configuration statements.
// Character types.
#[cfg(any(target_os="android", target_os="emscripten",
all(target_os="linux",
any(target_arch="aarch64", target_arch="arm",
target_arch="powerpc", target_arch="powerpc64"))))]
pub type CChar = u8;
#[cfg(not(any(target_os="android", target_os="emscripten",
all(target_os="linux",
any(target_arch="aarch64", target_arch="arm",
target_arch="powerpc", target_arch="powerpc64")))))]
pub type CChar = i8;
pub type CUChar = u8;
// Integer types.
#[cfg(any(target_pointer_width="32", target_os="windows"))]
pub type CLong = i32;
#[cfg(any(target_pointer_width="32", target_os="windows"))]
pub type CULong = u32;
#[cfg(all(target_pointer_width="64", not(target_os="windows")))]
pub type CLong = i32;
#[cfg(all(target_pointer_width="64", not(target_os="windows")))]
pub type CULong = u32;
pub type CShort = i16;
pub type CUShort = u16;
pub type CInt = i32;
pub type CUInt = u32;
pub type CLongLong = i64;
pub type CULongLong = u64;
pub type CFloat = f32;
pub type CDouble = f64;
// Void types.
/// To return void from a 'C' function it should return an empty tuple ().
/// This type is just a descriptive version of that. **DO NOT** use this
2017-04-06 17:28:02 -04:00
/// as an argument to a function. Use the CVoid type for that.
pub type CReturnVoid = ();
/// This acts as a 'C' void pointer to pass to functions. **DO NOT**
/// use this as a return type from a 'C' function. If a 'C' function
2017-04-06 17:28:02 -04:00
/// returns void, then use the CReturnVoid type for that.
#[repr(u8)]
pub enum CVoid
{
#[doc(hidden)]
_Variant,
#[doc(hidden)]
_Variant2
}
// String types.
/*
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
pub struct CString
{
chars: Box<[u8]>
}
#[derive(Hash)]
pub struct CStr
{
inner: [CChar]
}
*/
#[cfg(feature="use_std")]
pub type CStr = ::std::ffi::CStr;
#[cfg(feature="use_std")]
pub type CString = ::std::ffi::CString;
#[cfg(feature="use_std")]
pub type NullByteError = ::std::ffi::NulError;