Struct Error

Source
pub struct Error { /* private fields */ }
Expand description

An error encountered during attribute parsing.

Given that most errors darling encounters represent code bugs in dependent crates, the internal structure of the error is deliberately opaque.

Implementations§

Source§

impl Error

Error creation functions

Source

pub fn custom<T: Display>(msg: T) -> Self

Creates a new error with a custom message.

Source

pub fn duplicate_field(name: &str) -> Self

Creates a new error for a field that appears twice in the input.

Source

pub fn missing_field(name: &str) -> Self

Creates a new error for a non-optional field that does not appear in the input.

Source

pub fn unknown_field(name: &str) -> Self

Creates a new error for a field name that appears in the input but does not correspond to a known field.

Source

pub fn unknown_field_with_alts<'a, T, I>(field: &str, alternates: I) -> Self
where T: AsRef<str> + 'a, I: IntoIterator<Item = &'a T>,

Creates a new error for a field name that appears in the input but does not correspond to a known attribute. The second argument is the list of known attributes; if a similar name is found that will be shown in the emitted error message.

Source

pub fn unsupported_shape(shape: &str) -> Self

Creates a new error for a struct or variant that does not adhere to the supported shape.

Source

pub fn unsupported_format(format: &str) -> Self

Source

pub fn unexpected_type(ty: &str) -> Self

Creates a new error for a field which has an unexpected literal type.

Source

pub fn unexpected_lit_type(lit: &Lit) -> Self

Creates a new error for a field which has an unexpected literal type. This will automatically extract the literal type name from the passed-in Lit and set the span to encompass only the literal value.

Source

pub fn unknown_value(value: &str) -> Self

Creates a new error for a value which doesn’t match a set of expected literals.

Source

pub fn too_few_items(min: usize) -> Self

Creates a new error for a list which did not get enough items to proceed.

Source

pub fn too_many_items(max: usize) -> Self

Creates a new error when a list got more items than it supports. The max argument is the largest number of items the receiver could accept.

Source

pub fn multiple(errors: Vec<Error>) -> Self

Bundle a set of multiple errors into a single Error instance.

§Panics

This function will panic if errors.is_empty() == true.

Source§

impl Error

Error instance methods

Source

pub fn has_span(&self) -> bool

Check if this error is associated with a span in the token stream.

Source

pub fn with_span<T: Spanned>(self, node: &T) -> Self

Tie a span to the error if none is already present. This is used in darling::FromMeta and other traits to attach errors to the most specific possible location in the input source code.

All darling-built impls, either from the crate or from the proc macro, will call this when appropriate during parsing, so it should not be necessary to call this unless you have overridden:

  • FromMeta::from_meta
  • FromMeta::from_nested_meta
  • FromMeta::from_value
Source

pub fn flatten(self) -> Self

Recursively converts a tree of errors to a flattened list.

Source

pub fn at<T: Display>(self, location: T) -> Self

Adds a location to the error, such as a field or variant. Locations must be added in reverse order of specificity.

Source

pub fn len(&self) -> usize

Gets the number of individual errors in this error.

This function never returns 0, as it’s impossible to construct a multi-error from an empty Vec.

Source

pub fn write_errors(self) -> TokenStream

Write this error and any children as compile errors into a TokenStream to be returned by the proc-macro.

Return these tokens unmodified to avoid disturbing the attached span information.

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§

fn cause(&self) -> Option<&dyn StdError>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl IntoIterator for Error

Source§

type Item = Error

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl !Send for Error

§

impl !Sync for Error

§

impl Unpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.