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 byte-aligned enum without a #[catch_all] variant: 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§
§value: u128The unrecognized value.
type_name: &'static strThe name of the enum that rejected it.
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
Source§fn eq(&self, other: &UnknownDiscriminant) -> bool
fn eq(&self, other: &UnknownDiscriminant) -> bool
Tests for
self and other values to be equal, and is used by ==.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