Macro TryFrom
macro_rules! TryFrom { ... }
What #[derive(TryFrom)] generates
Derive TryFrom allows you to convert enum discriminants into their corresponding variants.
Enums
By default, a TryFrom<isize> is generated, matching the type of the discriminant.
The type can be changed with a #[repr(u/i*)] attribute, e.g., #[repr(u8)] or #[repr(i32)].
Only field-less variants can be constructed from their variant, therefore the TryFrom implementation will return an error for a discriminant representing a variant with fields.
# use TryFrom;
#
assert_eq!;
assert_eq!;
assert_eq!;
// Variants with fields are not supported, as the value for their fields would be undefined.
assert!;