Macro nanbox::make_nanbox
[−]
[src]
macro_rules! make_nanbox { ( $(#[$meta:meta])* pub unsafe enum $name: ident, $enum_name: ident { $($field: ident ($typ: ty)),* } ) => { ... }; }
Creates an enum
which is packed into the signaling NaN representation of f64
.
Some limitations apply to make this work in a safe manner.
- The first and only the first variant must hold a
f64
. - There must be 8 or fewer variants in the defined enum (this is only checked with
debug_assert!
) - Pointers stored in a nanbox must only use the lower 48 bits (checked via
debug_assert!
only).
#[macro_use] extern crate nanbox; // Creates one `nanbox` type called `Value` and one normal enum called `Variant`. // `From` implementations are generated to converted between these two types as well as `From` // implementation for each of the types in the match arms (`From<f64>` etc). make_nanbox!{ pub unsafe enum Value, Variant { Float(f64), Byte(u8), Int(i32), Pointer(*mut Value) } }