You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs.md
+13-3Lines changed: 13 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,10 +133,12 @@ You can learn about all of the different repr attributes [by reading Rust's refe
133
133
134
134
*`#[repr(C)]`: give this struct/union/enum the same layout and ABI C would
135
135
*`#[repr(u8, u16, ... etc)]`: give this enum the same layout and ABI as the given integer type
136
-
*`#[repr(transparent)]`: give this single-field struct the same ABI as its field (useful for newtyping integers but keeping the integer ABI)
136
+
*`#[repr(transparent)]`: give this single-field struct or enum the same ABI as its field (useful for newtyping integers but keeping the integer ABI)
137
137
138
138
cbindgen supports the `#[repr(align(N))]` and `#[repr(packed)]` attributes, but currently does not support `#[repr(packed(N))]`.
139
139
140
+
cbindgen supports using `repr(transparent)` on single-field structs and single-variant enums with fields. Transparent structs and enums are exported as typedefs that alias the underlying single field's type.
141
+
140
142
cbindgen also supports using `repr(C)`/`repr(u8)` on non-C-like enums (enums with fields). This gives a C-compatible tagged union layout, as [defined by this RFC 2195][really-tagged-unions]. `repr(C)` will give a simpler layout that is perhaps more intuitive, while `repr(u8)` will produce a more compact layout.
141
143
142
144
If you ensure everything has a guaranteed repr, then cbindgen will generate definitions for:
@@ -407,9 +409,17 @@ The rest are just local overrides for the same options found in the cbindgen.tom
407
409
408
410
### Enum Annotations
409
411
410
-
* enum-trailing-values=\[variant1, variant2, ...\] -- add the following fieldless enum variants to the end of the enum's definition. These variant names *will* have the enum's renaming rules applied.
412
+
* enum-trailing-values=\[variant1, variant2, ...\] -- add the following fieldless enum variants to
413
+
the end of the enum's definition. These variant names *will* have the enum's renaming rules
414
+
applied.
415
+
416
+
WARNING: if any of these values are ever passed into Rust, behaviour will be Undefined. Rust does
417
+
not know about them, and will assume they cannot happen.
411
418
412
-
WARNING: if any of these values are ever passed into Rust, behaviour will be Undefined. Rust does not know about them, and will assume they cannot happen.
419
+
* transparent-typedef -- when emitting the typedef for a transparent enum, mark it as
420
+
transparent. All references to the enum will be replaced with the type of its underlying NZST
421
+
variant field, effectively making the enum invisible on the FFI side. For exmaples of how this
422
+
works, see [Struct Annotations](#struct-annotations).
413
423
414
424
The rest are just local overrides for the same options found in the cbindgen.toml:
0 commit comments