pub enum ParseError {
Unknown(String),
}
Expand description
Creates C-like enums which preserve unknown (un-enumerated) values.
If you wanted an enum like:
#[repr(u32)]
pub enum HardenedBool {
True = 0x739,
False = 0x146,
Unknown(u32),
}
Where the Unknown
discriminator would be the catch-all for any
non-enumerated values, you can use with_unknown!
as follows:
with_unknown! {
pub enum HardenedBool: u32 {
True = 0x739,
False = 0x14d,
}
}
This “enum” can be used later in match statements:
match foo {
HardenedBool::True => do_the_thing(),
HardenedBool::False => do_the_opposite_thing(),
HardenedBool(x) => panic!("Oh noes! {} is neither True nor False!", x),
}
Behind the scenes, with_unknown!
implements a newtype struct and
creates associated constants for each of the enumerated values.
The struct also implements Copy
, Clone
, PartialEq
, Eq
,
PartialOrd
, Ord
, Hash
, Debug
and Display
(including the hex,
octal and binary versions).
In addition, serde::Serialize
and serde::Deserialize
are
implemented. The serialized form is a string for known values and an
integer for all unknown values.
Variants§
Trait Implementations§
Source§impl Debug for ParseError
impl Debug for ParseError
Source§impl Display for ParseError
impl Display for ParseError
Source§impl Error for ParseError
impl Error for ParseError
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()
Auto Trait Implementations§
impl Freeze for ParseError
impl RefUnwindSafe for ParseError
impl Send for ParseError
impl Sync for ParseError
impl Unpin for ParseError
impl UnwindSafe for ParseError
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