Support C-style enums
This adds support for passing C-style enums between Rust and C++.
We use the Rust representation for enums suggested by dtolnay in #132.
Note that as this does not use real enums, Rust code cannot treat them
as normal enums, e.g., by converting them to integers. But common
uses such as pattern matching remain unchanged.
diff --git a/syntax/mod.rs b/syntax/mod.rs
index a4b0ac4..9b1a7e5 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -29,6 +29,7 @@
pub enum Api {
Include(LitStr),
Struct(Struct),
+ Enum(Enum),
CxxType(ExternType),
CxxFunction(ExternFn),
RustType(ExternType),
@@ -50,6 +51,14 @@
pub fields: Vec<Var>,
}
+pub struct Enum {
+ pub doc: Doc,
+ pub enum_token: Token![enum],
+ pub ident: Ident,
+ pub brace_token: Brace,
+ pub variants: Vec<Variant>,
+}
+
pub struct ExternFn {
pub lang: Lang,
pub doc: Doc,
@@ -83,6 +92,11 @@
pub shorthand: bool,
}
+pub struct Variant {
+ pub ident: Ident,
+ pub discriminant: Option<u32>,
+}
+
pub enum Type {
Ident(Ident),
RustBox(Box<Ty1>),