surjective-enum 0.1.0

Rust macro to derive a surjective mapping from enum representation to enum.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 8.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 279.27 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • freylax/surjective-enum
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • freylax

surjective-enum

Rust macro to derive a surjective mapping from enum representation to enum.

Build Status

Derive a surjective ::core::convert::From conversion function which maps all values which are not part of the enumeration to the last enum discriminant.

The example

use surjective_enum::From;
#[repr(u8)]
#[derive(From)]
pub enum Enum {
	Bar  = 0b00,
	Foo  = 0b01,
	Rest = 0b11
}

will create a from(u8) -> Enum conversion function which maps 0 -> Bar, 1 -> Foo and all other values to Rest.