Skip to content

Commit 29546dd

Browse files
committed
remove claim about searching through nested fields for the nullable type, even though that is how it works
1 parent 1319b29 commit 29546dd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/doc/book/ffi.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,12 @@ interfacing with C, pointers that might be `null` are often used, which would se
581581
require some messy `transmute`s and/or unsafe code to handle conversions to/from Rust types.
582582
However, the language provides a workaround.
583583

584-
As a special case, an `enum` is eligible for the "nullable pointer optimization" if it
585-
contains exactly two variants, one of which contains no data and the other contains
586-
a field of one of the non-nullable types listed above (or a struct containing such a type).
587-
This means no extra space is required for a discriminant; rather, the empty variant is represented
588-
by putting a `null` value into the non-nullable field. This is called an "optimization", but unlike
589-
other optimizations it is guaranteed to apply to eligible types.
584+
As a special case, an `enum` is eligible for the "nullable pointer optimization" if it contains
585+
exactly two variants, one of which contains no data and the other contains a field of one of the
586+
non-nullable types listed above. This means no extra space is required for a discriminant; rather,
587+
the empty variant is represented by putting a `null` value into the non-nullable field. This is
588+
called an "optimization", but unlike other optimizations it is guaranteed to apply to eligible
589+
types.
590590

591591
The most common type that takes advantage of the nullable pointer optimization is `Option<T>`,
592592
where `None` corresponds to `null`. So `Option<extern "C" fn(c_int) -> c_int>` is a correct way
@@ -599,7 +599,9 @@ and an integer and it is supposed to run the function with the integer as a para
599599
we have function pointers flying across the FFI boundary in both directions.
600600

601601
```rust
602-
use std::os::raw::c_int;
602+
# #![feature(libc)]
603+
extern crate libc;
604+
use libc::c_int;
603605

604606
# #[cfg(hidden)]
605607
extern "C" {

0 commit comments

Comments
 (0)