@@ -578,19 +578,17 @@ interfacing with C, pointers that might be `null` are often used, which would se
578
578
require some messy ` transmute ` s and/or unsafe code to handle conversions to/from Rust types.
579
579
However, the language provides a workaround.
580
580
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
587
586
eligible types.
588
587
589
588
The most common type that takes advantage of the nullable pointer optimization is ` Option<T> ` ,
590
589
where ` None ` corresponds to ` null ` . So ` Option<extern "C" fn(c_int) -> c_int> ` is a correct way
591
590
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) ` ).
594
592
595
593
Here is an example:
596
594
0 commit comments