#[non_exhaustive]pub enum BuilderError {
MissingField(&'static str),
Invalid(String),
}Expand description
The error a generated builder’s build() returns.
Two cases:
MissingField— a required field was never set. “Required” is the default; a field is only optional if it carries#[builder(default)](or#[builder(default = expr)]). This is what lets the builder call out an unset bit/byte instead of silently defaulting it to zero (the gap in the infixwith_*API).Invalid— a#[bin(validate = …)]soundness check rejected the built value. The string is the validator’s error, stringified, so anyDisplayerror type composes without coupling the builder to a protocol-specific error type.
§Examples
use bnb::{bitfield, u4, BitsBuilder, BuilderError};
#[bitfield(u8, bits = msb)]
#[derive(BitsBuilder, Clone, Copy, Debug)]
struct Nibbles { hi: u4, lo: u4 }
let err = Nibbles::builder().hi(u4::new(0xA)).build().unwrap_err();
assert_eq!(err, BuilderError::MissingField("lo"));
assert_eq!(err.field(), Some("lo"));
assert_eq!(err.to_string(), "required field `lo` was not set");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
MissingField(&'static str)
A required field was not set; carries the field name.
Invalid(String)
A soundness validator rejected the value; carries its message.
Implementations§
Source§impl BuilderError
impl BuilderError
Trait Implementations§
Source§impl Clone for BuilderError
impl Clone for BuilderError
Source§fn clone(&self) -> BuilderError
fn clone(&self) -> BuilderError
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 BuilderError
impl Debug for BuilderError
Source§impl Display for BuilderError
impl Display for BuilderError
impl Eq for BuilderError
Source§impl Error for BuilderError
impl Error for BuilderError
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 BuilderError
impl PartialEq for BuilderError
impl StructuralPartialEq for BuilderError
Auto Trait Implementations§
impl Freeze for BuilderError
impl RefUnwindSafe for BuilderError
impl Send for BuilderError
impl Sync for BuilderError
impl Unpin for BuilderError
impl UnsafeUnpin for BuilderError
impl UnwindSafe for BuilderError
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