discrim 0.1.2

Construct enum variants from their tag
Documentation
1
2
3
4
5
6
7
8
9
10
b0VIM 9.0O֋d+��@lafrancecedar-4.attlocal.net~lafrance/Dev/Misc/discrim/discrim/src/lib.rsutf-8
3210#"! Utp#ad�	W
#��H���
�
�
�
�
�
�
Y
I
7



����ih������
�
Y
W
U
,


} }}    fn from_val(val: T) -> Opt}    fn from_val(val: T) -> Option<Self>}}    fn from_discriminant(discrim: T) -> Result<Self, T>;pub trait FromDiscriminant<T>: Sized {/// See the docs for either the crate root or the derive macro for usage examples of this trait./// You should never implement this trait yourself; use the [derive macro](discrim_codegen::FromDiscriminant) instead.////// Initialize enum values from their discriminant.// Neither trait should ever be manually implemented// TODO: better error handling, specifically maybe a more robust type than just storing the errant valuepub use discrim_codegen::FromDiscriminant;//! ```//! assert_eq!(Opcode::from_discriminant(5), Err(5));//! assert_eq!(Opcode::from_discriminant(2), Ok(Opcode::Mul));//!//! }//!     Add, Sub, Mul, Div//! enum Opcode {//! #[repr(u8)]//! #[derive(Debug, FromDiscriminant, PartialEq)]//!//! use discrim::FromDiscriminant;//! ```rust//! Given an enum that fits these constraints://! # Usage//!//! the giant match block required to initialize the enum from a discriminant value as an implementation of [`FromDiscriminant`].//! Basically, for fieldless, non-generic enums with a `#[repr(...)]` specified, the derive macro generates//!//! for automatically generating code to initialize enum values from their discriminant.//! This crate provides the [`FromDiscriminant`] trait and associated [derive macro](discrim_codegen::FromDiscriminant)//!//! Automatically initialize enum variants by discriminant.