Adding macro definitions for declaring C structures and pointers.
This commit is contained in:
parent
95361a80e2
commit
3bc41bae4f
15
src/c_ptr.rs
Normal file
15
src/c_ptr.rs
Normal 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
18
src/c_struct.rs
Normal 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),+,
|
||||
}
|
||||
};
|
||||
}
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user