Merge pull request #273 from JohnTitor/mention-extern-types

Mention "extern types" on the opaque structs section
pull/284/head
Eric Huss 3 years ago committed by GitHub
commit 2e159b0d30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -703,9 +703,8 @@ for more information.
## Representing opaque structs ## Representing opaque structs
Sometimes, a C library wants to provide a pointer to something, but not let you Sometimes, a C library wants to provide a pointer to something, but not let you know the internal details of the thing it wants.
know the internal details of the thing it wants. The simplest way is to use a A stable and simple way is to use a `void *` argument:
`void *` argument:
```c ```c
void foo(void *arg); void foo(void *arg);
@ -774,3 +773,9 @@ Notice that it is a really bad idea to use an empty enum as FFI type.
The compiler relies on empty enums being uninhabited, so handling values of type The compiler relies on empty enums being uninhabited, so handling values of type
`&Empty` is a huge footgun and can lead to buggy program behavior (by triggering `&Empty` is a huge footgun and can lead to buggy program behavior (by triggering
undefined behavior). undefined behavior).
> **NOTE:** The simplest way would use "extern types".
But it's currently (as of June 2021) unstable and has some unresolved questions, see the [RFC page][extern-type-rfc] and the [tracking issue][extern-type-issue] for more details.
[extern-type-issue]: https://github.com/rust-lang/rust/issues/43467
[extern-type-rfc]: https://rust-lang.github.io/rfcs/1861-extern-types.html

Loading…
Cancel
Save