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
impl Error
Error creation functions
Sourcepub fn duplicate_field(name: &str) -> Self
pub fn duplicate_field(name: &str) -> Self
Creates a new error for a field that appears twice in the input.
Sourcepub fn missing_field(name: &str) -> Self
pub fn missing_field(name: &str) -> Self
Creates a new error for a non-optional field that does not appear in the input.
Sourcepub fn unknown_field(name: &str) -> Self
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.
Sourcepub fn unknown_field_with_alts<'a, T, I>(field: &str, alternates: I) -> Self
pub fn unknown_field_with_alts<'a, T, I>(field: &str, alternates: I) -> Self
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.
Sourcepub fn unsupported_shape(shape: &str) -> Self
pub fn unsupported_shape(shape: &str) -> Self
Creates a new error for a struct or variant that does not adhere to the supported shape.
pub fn unsupported_format(format: &str) -> Self
Sourcepub fn unexpected_type(ty: &str) -> Self
pub fn unexpected_type(ty: &str) -> Self
Creates a new error for a field which has an unexpected literal type.
Sourcepub fn unexpected_lit_type(lit: &Lit) -> Self
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.
Sourcepub fn unknown_value(value: &str) -> Self
pub fn unknown_value(value: &str) -> Self
Creates a new error for a value which doesn’t match a set of expected literals.
Sourcepub fn too_few_items(min: usize) -> Self
pub fn too_few_items(min: usize) -> Self
Creates a new error for a list which did not get enough items to proceed.
Sourcepub fn too_many_items(max: usize) -> Self
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§impl Error
Error instance methods
impl Error
Error instance methods
Sourcepub fn has_span(&self) -> bool
pub fn has_span(&self) -> bool
Check if this error is associated with a span in the token stream.
Sourcepub fn with_span<T: Spanned>(self, node: &T) -> Self
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_metaFromMeta::from_nested_metaFromMeta::from_value
Sourcepub fn at<T: Display>(self, location: T) -> Self
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.
Sourcepub fn len(&self) -> usize
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.
Sourcepub fn write_errors(self) -> TokenStream
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.