Skip to content

Commit 48ce206

Browse files
committed
generics-agnostic description
1 parent 032ea41 commit 48ce206

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/doc/book/ffi.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,19 +578,17 @@ interfacing with C, pointers that might be `null` are often used, which would se
578578
require some messy `transmute`s and/or unsafe code to handle conversions to/from Rust types.
579579
However, the language provides a workaround.
580580

581-
As a special case, an `enum` that contains exactly two variants, one of
582-
which contains no data and the other containing a single field, is eligible
583-
for the "nullable pointer optimization". When such an enum is instantiated
584-
with one of the non-nullable types listed above, it is represented as a single pointer,
585-
and the non-data variant is represented as the null pointer. This is called an
586-
"optimization", but unlike other optimizations it is guaranteed to apply to
581+
As a special case, an `enum` is eligible for the "nullable pointer optimization" if it
582+
contains exactly two variants, one of which contains no data and the other contains
583+
a single field of one of the non-nullable types listed above. This means it is represented
584+
as a single pointer, and the non-data variant is represented as the null pointer. This is
585+
called an "optimization", but unlike other optimizations it is guaranteed to apply to
587586
eligible types.
588587

589588
The most common type that takes advantage of the nullable pointer optimization is `Option<T>`,
590589
where `None` corresponds to `null`. So `Option<extern "C" fn(c_int) -> c_int>` is a correct way
591590
to represent a nullable function pointer using the C ABI (corresponding to the C type
592-
`int (*)(int)`). (However, generics are not required to get the optimization. A simple
593-
`enum NullableIntRef { Int(Box<i32>), NotInt }` is also represented as a single pointer.)
591+
`int (*)(int)`).
594592

595593
Here is an example:
596594

0 commit comments

Comments
 (0)