#[non_exhaustive]pub struct UnknownDiscriminant {
pub value: u128,
pub type_name: &'static str,
}Expand description
The error returned by the TryFrom<uN> impl that #[derive(BitEnum)]
generates for a primitive-width enum without a #[catch_all] variant
(width u8/u16/u32/u64/u128): the value matched no known discriminant.
A catch-all enum is total, so its primitive→enum conversion is an infallible
From and never produces this. This mirrors num_enum’s
TryFromPrimitiveError. Decoding through the codec / Bits::from_bits is
unaffected — that path stays permissive (dual-use); this is only for the
caller who opts into a checked conversion.
§Examples
#[derive(bnb::BitEnum, Clone, Copy, Debug, PartialEq, Eq)]
#[bit_enum(u8, closed)]
#[repr(u8)]
enum Direction { Request = 1, Reply = 2 }
let err = Direction::try_from(9u8).unwrap_err(); // no variant for 9
assert_eq!(err.value, 9);
assert_eq!(err.type_name, "Direction");
assert_eq!(err.to_string(), "Direction has no variant for discriminant 9");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.value: u128The unrecognized value.
type_name: &'static strThe name of the enum that rejected it.
Implementations§
Trait Implementations§
Source§impl Clone for UnknownDiscriminant
impl Clone for UnknownDiscriminant
Source§fn clone(&self) -> UnknownDiscriminant
fn clone(&self) -> UnknownDiscriminant
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UnknownDiscriminant
impl Debug for UnknownDiscriminant
Source§impl Display for UnknownDiscriminant
impl Display for UnknownDiscriminant
impl Eq for UnknownDiscriminant
Source§impl Error for UnknownDiscriminant
impl Error for UnknownDiscriminant
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl PartialEq for UnknownDiscriminant
impl PartialEq for UnknownDiscriminant
impl StructuralPartialEq for UnknownDiscriminant
Auto Trait Implementations§
impl Freeze for UnknownDiscriminant
impl RefUnwindSafe for UnknownDiscriminant
impl Send for UnknownDiscriminant
impl Sync for UnknownDiscriminant
impl Unpin for UnknownDiscriminant
impl UnsafeUnpin for UnknownDiscriminant
impl UnwindSafe for UnknownDiscriminant
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more