Enum Ptr

crates.io docs.rs

This crate provides a custom derive macro EnumPtr to automatically generate bridges between T and Compact<T> with the minimum cost. Compact<T> is the compact representation of T, and it is only one pointer wide.

For example, the following code

```rust use enum_ptr::EnumPtr;

[derive(EnumPtr)]

[repr(C, usize)]

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

will generate

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

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

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

Testing

console $ cargo test $ cargo +nightly miri test

Credits

License

This project is licensed under either of

at your option.