| Crates.io | enum_parity |
| lib.rs | enum_parity |
| version | 0.2.0 |
| created_at | 2025-12-31 04:38:39.417405+00 |
| updated_at | 2026-01-04 01:10:02.688964+00 |
| description | a macro that enforces enum discriminant bit parity |
| homepage | |
| repository | https://github.com/przb/enum_parity |
| max_upload_size | |
| id | 2013907 |
| size | 69,113 |
This crate exposes a macro to enforce enum discriminants with a given bit parity. Using even or odd bit parity enforces a Hamming weight of two.
How to use with Cargo:
[dependencies]
enum_parity = "0.2.0"
To use in your crate:
use enum_parity::bit_parity;
#[repr(u8)]
#[bit_parity(even)]
pub enum EvenParitySample {
Foo,
Bar,
Baz,
Quo,
}
#[repr(u8)]
#[bit_parity(odd)]
pub enum OddParitySample {
Lorem,
Ipsum,
Dolor,
Sit,
}
This gets expanded to have the given bit parity as follows:
#[repr(u8)]
pub enum EvenParitySample {
Foo = 0u8,
Bar = 3u8,
Baz = 5u8,
Quo = 6u8,
}
#[repr(u8)]
pub enum OddParitySample {
Lorem = 1u8,
Ipsum = 2u8,
Dolor = 4u8,
Sit = 7u8,
}
Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 or the MIT license https://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.