Crates.io | addr_of_enum |
lib.rs | addr_of_enum |
version | 0.1.5 |
source | src |
created_at | 2024-01-01 07:32:54.699292 |
updated_at | 2024-02-12 09:39:40.391061 |
description | Get address of fields in enum item using stable Rust |
homepage | |
repository | https://github.com/yasuo-ozu/addr_of_enum |
max_upload_size | |
id | 1085206 |
size | 5,285 |
This crate provides #[derive(AddrOfEnum)]
and addr_of_enum!
macro to get a field pointer of specified variant without creating an intermediated reference. It works like std::ptr::addr_of!
, but works only on enums.
This macro is zero-cost, which means that it calculates without minimum cost in release mode.
It also works on variables which has uninhabited types.
# use addr_of_enum::{addr_of_enum, AddrOfEnum};
#[derive(AddrOfEnum)]
#[repr(C)]
enum MyEnum {
E1(usize, u8),
E2 {
item1: u32,
item2: u8,
}
}
let e = MyEnum::E1(1, 2);
let _: *const usize = addr_of_enum!(&e, E1, 0);
let _: *const u32 = addr_of_enum!(&e, E2, item1);
For now, the macros cannot be used in const context.