Add enum_class option

This option allows specifying that a C++ enum should be emitted with
plain `enum` rather than `enum class`. It's true that `enum class` should
generally be preferred, but sometimes there's existing code which is
already using plain `enum`, and porting that code to Rust becomes easier when
`cbindgen` can emit plain `enum`.

This option can be overridden on a per-enum basis using a `cbindgen:` annotation.

It defaults to true for two reasons:

* Backward compatibility.
* `enum class` is probably actually what you want, in general.
This commit is contained in:
Evan Shaw
2019-12-29 18:39:12 +13:00
committed by Emilio Cobos Álvarez
parent 16fe3ec142
commit 6a9066f7cd
12 changed files with 272 additions and 12 deletions
+30 -1
View File
@@ -58,6 +58,20 @@ enum class M : int8_t {
m3 = 1,
};
enum N {
n1,
n2,
n3,
n4,
};
enum O : int8_t {
o1,
o2,
o3,
o4,
};
struct J;
struct K;
@@ -137,6 +151,21 @@ struct I {
extern "C" {
void root(Opaque *o, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m);
void root(Opaque *opaque,
A a,
B b,
C c,
D d,
E e,
F f,
G g,
H h,
I i,
J j,
K k,
L l,
M m,
N n,
O o);
} // extern "C"