Enum Ptr

This crate provides a custom derive macro EnumPtr to automatically generate bridges between T and Compact<T> with minimum cost. For example, the following code

```rust use enum_ptr::EnumPtr;

[derive(EnumPtr)]

[repr(C, usize)]

enum Foo<'a> { A(&'a i32), B(Option>), } ```

will generate

```rust impl<'a> From> for enum_ptr::Compact> { // ... }

impl<'a> From>> for Foo<'a> { // ... } ```

where Compact<Foo<'a>> is the compact representation of Foo<'a>. It is only one pointer wide.

Since &i32 and Box<i32> are aligned by 4 bytes, the lowest 2 bits of them are always zeros. Compact<Foo<'a>> utilizes these bits to store the tag (discriminant value).

Features

Usage

Dependencies

toml [dependencies] enum-ptr = "*"

This crate also supports no_std.

toml [dependencies] enum-ptr = { version = "*", default-features = false }

Code

See docs.rs

Credits

License

This project is licensed under either of

at your option.