enum_parity 0.1.1

a macro that enforces enum discriminant bit parity
Documentation

Enum Bit Parity

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.

Example and Usage

How to use with Cargo:

[dependencies]
enum_parity = "0.1.0"

To use in your crate:

use enum_parity::bit_parity;

#[bit_parity(even)]
#[repr(u8)]
pub enum EvenParitySample {
    Foo,
    Bar,
    Baz,
    Quo,
}

#[bit_parity(odd)]
#[repr(u8)]
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,
}

License

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.