Adding macro definitions for declaring C structures and pointers.

This commit is contained in:
Myrddin Dundragon 2019-06-25 02:31:18 -04:00
parent 95361a80e2
commit 3bc41bae4f
3 changed files with 35 additions and 0 deletions

15
src/c_ptr.rs Normal file
View File

@ -0,0 +1,15 @@
/// A C Pointer to an undefined structure.
///
/// A lot of C libraries return a pointer to an undefined structure.
/// This is easily wrapped as an empty enum. This keeps users from being
/// able to create an instance of the value.
#[macro_export]
macro_rules! c_ptr
{
{
$name: ident
} =>
{
pub enum $name {}
};
}

18
src/c_struct.rs Normal file
View File

@ -0,0 +1,18 @@
/// Defines a C style structure.
#[macro_export]
macro_rules! c_struct
{
{
$cname: ident
{
$($name: ident: $type: ty);*;
}
} =>
{
#[repr(C)]
pub struct $cname
{
$(pub $name: $type),+,
}
};
}

View File

@ -22,6 +22,8 @@ mod macros;
// Basic C type macro modules.
mod c_enum;
mod c_flags;
mod c_ptr;
mod c_struct;
mod c_types;
// Raw platform data retrieval.