pub struct EnumFromBytesError {
pub invalid_discriminant: Discriminant,
pub enum_type_name: &'static str,
}Expand description
Error type for converting bytes to an enum with an invalid discriminant.
This error is returned when attempting to convert a byte array to an enum value, but the discriminant value doesn’t match any valid enum variant.
The error includes both the invalid discriminant value (with its original type) and the enum type name for better diagnostics.
§Examples
use byteable::{Byteable, TryFromByteArray, IntoByteArray};
#[derive(Byteable, Debug, Clone, Copy, PartialEq)]
#[repr(u8)]
enum Status {
Idle = 0,
Running = 1,
}
// Valid discriminant
let bytes = [1];
let status = Status::try_from_byte_array(bytes).unwrap();
assert_eq!(status, Status::Running);
// Invalid discriminant
let bytes = [255];
let result = Status::try_from_byte_array(bytes);
assert!(result.is_err());Fields§
§invalid_discriminant: DiscriminantThe invalid discriminant value that was encountered
enum_type_name: &'static strThe name of the enum type that failed to match
Implementations§
Source§impl EnumFromBytesError
impl EnumFromBytesError
Sourcepub fn new<T: Into<Discriminant>>(
invalid_discriminant: T,
enum_type_name: &'static str,
) -> Self
pub fn new<T: Into<Discriminant>>( invalid_discriminant: T, enum_type_name: &'static str, ) -> Self
Creates a new EnumFromBytesError with the given invalid discriminant and type name.
Trait Implementations§
Source§impl Clone for EnumFromBytesError
impl Clone for EnumFromBytesError
Source§fn clone(&self) -> EnumFromBytesError
fn clone(&self) -> EnumFromBytesError
Returns a duplicate of the value. Read more
1.0.0 · 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 EnumFromBytesError
impl Debug for EnumFromBytesError
Source§impl Display for EnumFromBytesError
impl Display for EnumFromBytesError
Source§impl Error for EnumFromBytesError
Available on crate feature std only.
impl Error for EnumFromBytesError
Available on crate feature
std only.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 EnumFromBytesError
impl PartialEq for EnumFromBytesError
impl Copy for EnumFromBytesError
impl Eq for EnumFromBytesError
impl StructuralPartialEq for EnumFromBytesError
Auto Trait Implementations§
impl Freeze for EnumFromBytesError
impl RefUnwindSafe for EnumFromBytesError
impl Send for EnumFromBytesError
impl Sync for EnumFromBytesError
impl Unpin for EnumFromBytesError
impl UnwindSafe for EnumFromBytesError
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