[][src]Struct darling::Error

pub struct Error { /* fields omitted */ }

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.

Methods

impl Error[src]

Error creation functions

pub fn custom<T>(msg: T) -> Error where
    T: Display
[src]

Creates a new error with a custom message.

pub fn duplicate_field(name: &str) -> Error[src]

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

pub fn missing_field(name: &str) -> Error[src]

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

pub fn unknown_field(name: &str) -> Error[src]

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

pub fn unsupported_shape(shape: &str) -> Error[src]

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

pub fn unsupported_format(format: &str) -> Error[src]

pub fn unexpected_type(ty: &str) -> Error[src]

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

pub fn unknown_value(value: &str) -> Error[src]

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

pub fn too_few_items(min: usize) -> Error[src]

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

pub fn too_many_items(max: usize) -> Error[src]

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.

pub fn multiple(errors: Vec<Error>) -> Error[src]

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

Panics

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

impl Error[src]

Error instance methods

pub fn has_span(&self) -> bool[src]

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

pub fn set_span(&mut self, span: Span)[src]

Deprecated since 0.8.3:

Callers should not broaden error spans. Use with_span instead.

Override the source code location of this error with a new one.

pub fn with_span<T>(self, node: &T) -> Error where
    T: Spanned
[src]

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

pub fn flatten(self) -> Error[src]

Recursively converts a tree of errors to a flattened list.

pub fn at<T>(self, location: T) -> Error where
    T: Display
[src]

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

pub fn len(&self) -> usize[src]

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.

pub fn write_errors(self) -> TokenStream[src]

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

The behavior of this method will be slightly different if the diagnostics feature is enabled: In that case, the diagnostics will be emitted immediately by this call, and an empty TokenStream will be returned.

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

Usage

This example is not tested
// in your proc-macro function
let opts = match MyOptions::from_derive_input(&ast) {
    Ok(val) => val,
    Err(err) => {
        return err.write_errors();
    }
}

Trait Implementations

impl Display for Error[src]

impl Error for Error[src]

fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0
[src]

The lower-level source of this error, if any. Read more

impl Debug for Error[src]

impl IntoIterator for Error[src]

type Item = Error

The type of the elements being iterated over.

type IntoIter = IntoIter

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl !Send for Error

impl !Sync for Error

Blanket Implementations

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]