| Crates.io | betterunion |
| lib.rs | betterunion |
| version | 0.1.1 |
| created_at | 2025-08-30 17:40:36.297882+00 |
| updated_at | 2025-08-30 20:51:36.297722+00 |
| description | This crate provides a safe union-like structure which uses the turbofish operator for reads and writes. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1817797 |
| size | 7,128 |
betterunion is crate which provides a safe zero-cost way of storing types as raw data which can later be reinterpreted, only types which implement bytemuck's Pod trait can be used in the read and write functions.
use betterunion::BetterUnion;
fn main() {
let mut u = BetterUnion::<8>::new();
u.write(42u32);
println!("{}", u.read_copy::<u64>());
let mut v = BetterUnion::<16>::new();
v.write(3.14f64);
println!("{}", v.read_copy::<f64>());
}