Trait darling_core::FromMeta
source · [−]pub trait FromMeta: Sized {
fn from_nested_meta(item: &NestedMeta) -> Result<Self> { ... }
fn from_meta(item: &Meta) -> Result<Self> { ... }
fn from_word() -> Result<Self> { ... }
fn from_list(items: &[NestedMeta]) -> Result<Self> { ... }
fn from_value(value: &Lit) -> Result<Self> { ... }
fn from_char(value: char) -> Result<Self> { ... }
fn from_string(value: &str) -> Result<Self> { ... }
fn from_bool(value: bool) -> Result<Self> { ... }
}
Expand description
Create an instance from an item in an attribute declaration.
Implementing FromMeta
- Do not take a dependency on the
ident
of the passed-in meta item. The ident will be set by the field name of the containing struct. - Implement only the
from_*
methods that you intend to support. The default implementations will return useful errors.
Provided Implementations
bool
- Word with no value specified - becomes
true
. - As a boolean literal, e.g.
foo = true
. - As a string literal, e.g.
foo = "true"
.
char
- As a char literal, e.g.
foo = '#'
. - As a string literal consisting of a single character, e.g.
foo = "#"
.
String
- As a string literal, e.g.
foo = "hello"
. - As a raw string literal, e.g.
foo = r#"hello "world""#
.
Number
- As a string literal, e.g.
foo = "-25"
. - As an unquoted positive value, e.g.
foo = 404
. Negative numbers must be in quotation marks.
()
- Word with no value specified, e.g.
foo
. This is best used withOption
. Seedarling::util::Flag
for a more strongly-typed alternative.
Option
- Any format produces
Some
.
Result<T, darling::Error>
- Allows for fallible parsing; will populate the target field with the result of the parse attempt.
Provided Methods
fn from_nested_meta(item: &NestedMeta) -> Result<Self>
Create an instance from a syn::Meta
by dispatching to the format-appropriate
trait function. This generally should not be overridden by implementers.
Error Spans
If this method is overridden and can introduce errors that weren’t passed up from
other from_meta
calls, the override must call with_span
on the error using the
item
to make sure that the emitted diagnostic points to the correct location in
source code.
Create an instance from the presence of the word in the attribute with no additional options specified.
sourcefn from_list(items: &[NestedMeta]) -> Result<Self>
fn from_list(items: &[NestedMeta]) -> Result<Self>
Create an instance from a list of nested meta items.
sourcefn from_value(value: &Lit) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
Create an instance from a literal value of either foo = "bar"
or foo("bar")
.
This dispatches to the appropriate method based on the type of literal encountered,
and generally should not be overridden by implementers.
Error Spans
If this method is overridden, the override must make sure to add value
’s span
information to the returned error by calling with_span(value)
on the Error
instance.
Create an instance from a char literal in a value position.
sourcefn from_string(value: &str) -> Result<Self>
fn from_string(value: &str) -> Result<Self>
Create an instance from a string literal in a value position.
Implementations on Foreign Types
sourceimpl FromMeta for u8
impl FromMeta for u8
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for u16
impl FromMeta for u16
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for u32
impl FromMeta for u32
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for u64
impl FromMeta for u64
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for usize
impl FromMeta for usize
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for i8
impl FromMeta for i8
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for i16
impl FromMeta for i16
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for i32
impl FromMeta for i32
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for i64
impl FromMeta for i64
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for isize
impl FromMeta for isize
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for f32
impl FromMeta for f32
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for f64
impl FromMeta for f64
fn from_string(s: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl<T: Parse, P: Parse> FromMeta for Punctuated<T, P>
impl<T: Parse, P: Parse> FromMeta for Punctuated<T, P>
Parsing support for punctuated. This attempts to preserve span information when available, but also supports parsing strings with the call site as the emitted span.
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Ident
impl FromMeta for Ident
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Expr
impl FromMeta for Expr
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for ExprArray
impl FromMeta for ExprArray
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for ExprPath
impl FromMeta for ExprPath
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Path
impl FromMeta for Path
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Type
impl FromMeta for Type
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeArray
impl FromMeta for TypeArray
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeBareFn
impl FromMeta for TypeBareFn
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeGroup
impl FromMeta for TypeGroup
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeImplTrait
impl FromMeta for TypeImplTrait
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeInfer
impl FromMeta for TypeInfer
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeMacro
impl FromMeta for TypeMacro
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeNever
impl FromMeta for TypeNever
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeParam
impl FromMeta for TypeParam
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeParen
impl FromMeta for TypeParen
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypePath
impl FromMeta for TypePath
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypePtr
impl FromMeta for TypePtr
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeReference
impl FromMeta for TypeReference
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeSlice
impl FromMeta for TypeSlice
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeTraitObject
impl FromMeta for TypeTraitObject
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for TypeTuple
impl FromMeta for TypeTuple
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Visibility
impl FromMeta for Visibility
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for WhereClause
impl FromMeta for WhereClause
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Vec<u8>
impl FromMeta for Vec<u8>
Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]"
.
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Vec<u16>
impl FromMeta for Vec<u16>
Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]"
.
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Vec<u32>
impl FromMeta for Vec<u32>
Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]"
.
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Vec<u64>
impl FromMeta for Vec<u64>
Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]"
.
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Vec<usize>
impl FromMeta for Vec<usize>
Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]"
.
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for LitByteStr
impl FromMeta for LitByteStr
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for Vec<WherePredicate>
impl FromMeta for Vec<WherePredicate>
fn from_string(value: &str) -> Result<Self>
fn from_value(value: &Lit) -> Result<Self>
sourceimpl FromMeta for RenameRule
impl FromMeta for RenameRule
fn from_string(value: &str) -> Result<Self>
sourceimpl<T: FromMeta> FromMeta for Result<T, Meta>
impl<T: FromMeta> FromMeta for Result<T, Meta>
Parses the meta-item, and in case of error preserves a copy of the input for later analysis.
sourceimpl<V: FromMeta, S: BuildHasher + Default> FromMeta for HashMap<String, V, S>
impl<V: FromMeta, S: BuildHasher + Default> FromMeta for HashMap<String, V, S>
fn from_list(nested: &[NestedMeta]) -> Result<Self>
sourceimpl<V: FromMeta, S: BuildHasher + Default> FromMeta for HashMap<Ident, V, S>
impl<V: FromMeta, S: BuildHasher + Default> FromMeta for HashMap<Ident, V, S>
fn from_list(nested: &[NestedMeta]) -> Result<Self>
sourceimpl<V: FromMeta, S: BuildHasher + Default> FromMeta for HashMap<Path, V, S>
impl<V: FromMeta, S: BuildHasher + Default> FromMeta for HashMap<Path, V, S>
fn from_list(nested: &[NestedMeta]) -> Result<Self>
Implementors
impl FromMeta for Flag
impl FromMeta for IdentString
impl FromMeta for Ignored
impl FromMeta for PathList
impl<T: FromMeta> FromMeta for Override<T>
Parses a Meta
. A bare word will produce Override::Inherit
, while
any value will be forwarded to T::from_meta
.