From 95361a80e235047034edd5c73dc73aaf9724f49c Mon Sep 17 00:00:00 2001 From: Jason Travis Smith Date: Tue, 25 Jun 2019 01:52:27 -0400 Subject: [PATCH] Finally nailed down the syntax of the external_library macro. --- src/lib.rs | 9 +++++---- src/macros.rs | 26 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5d30f58..098e477 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,9 @@ extern crate core as std; +// Macros to help create bindings to FFI libraries. +mod macros; + // Basic C type macro modules. mod c_enum; mod c_flags; @@ -24,15 +27,13 @@ mod c_types; // Raw platform data retrieval. mod raw; -// Macros to help create bindings to FFI libraries. -mod macros; +#[cfg(feature="use_std")] +pub use self::c_types::{CStr, CString, NullByteError}; pub use self::c_types::{CChar, CUChar}; pub use self::c_types::{CShort, CUShort, CInt, CUInt, CLong, CULong}; pub use self::c_types::{CLongLong, CULongLong, CFloat, CDouble}; pub use self::c_types::{CVoid, CReturnVoid}; -#[cfg(feature="use_std")] -pub use self::c_types::{CStr, CString, NullByteError}; pub use self::raw::{AsRaw, AsRawMut, AsRawPtr, AsRawMutPtr, FromRaw, IntoRaw}; diff --git a/src/macros.rs b/src/macros.rs index 23b295f..5a7c966 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -5,27 +5,33 @@ macro_rules! external_library $name: ident: $link: expr => { $(statics: - $($sname: ident: $stype: ty);+; - )|* + { + $($sname: ident: $stype: ty);+; + } + )? $(functions: - $($fname: ident($($farg: ident: $fargt: ty),*) -> $fret:ty);+; - )|* + { + $($fname: ident($($farg: ident: $fargt: ty),*) -> $fret:ty);+; + } + )? $(varargs: - $($vname: ident($($vargs: ident: $vargst: ty),+) -> $vret: ty);+; - )|* + { + $($vname: ident($($vargs: ident: $vargst: ty),+) -> $vret:ty);+; + } + )? } } => { #[link(name=$link)] extern "C" { - $($(pub static $sname: $stype;)+)* + $($(pub static $sname: $stype;)+)? - $($(pub fn $fname($($farg: $fargt),*) -> $fret;)+)* + $($(pub fn $fname($($farg: $fargt),*) -> $fret;)+)? - $($(pub fn $vname($(vargs: $vargst),+ , ...) -> $vret;)+)* + $($(pub fn $vname($(vargs: $vargst),+ , ...) -> $vret;)+)? } - } + }; }