pub trait FromMeta: Sized {
fn from_nested_meta(item: &NestedMeta) -> Result<Self, Error> { ... }
fn from_meta(item: &Meta) -> Result<Self, Error> { ... }
fn from_word() -> Result<Self, Error> { ... }
fn from_list(items: &[NestedMeta]) -> Result<Self, Error> { ... }
fn from_value(value: &Lit) -> Result<Self, Error> { ... }
fn from_char(value: char) -> Result<Self, Error> { ... }
fn from_string(value: &str) -> Result<Self, Error> { ... }
fn from_bool(value: bool) -> Result<Self, Error> { ... }
}
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"
.
String
- As a string literal, e.g.
foo = "hello"
. - As a raw string literal, e.g.
foo = r#"hello "world""#
.
()
- 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, Error>
sourcefn from_meta(item: &Meta) -> Result<Self, Error>
fn from_meta(item: &Meta) -> Result<Self, Error>
Create an instance from a syn::Meta
by dispatching to the format-appropriate
trait function. This generally should not be overridden by implementers.
sourcefn from_word() -> Result<Self, Error>
fn from_word() -> Result<Self, Error>
Create an instance from the presence of the word in the attribute with no additional options specified.
sourcefn from_list(items: &[NestedMeta]) -> Result<Self, Error>
fn from_list(items: &[NestedMeta]) -> Result<Self, Error>
Create an instance from a list of nested meta items.
sourcefn from_value(value: &Lit) -> Result<Self, Error>
fn from_value(value: &Lit) -> Result<Self, Error>
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.
sourcefn from_char(value: char) -> Result<Self, Error>
fn from_char(value: char) -> Result<Self, Error>
Create an instance from a char literal in a value position.
sourcefn from_string(value: &str) -> Result<Self, Error>
fn from_string(value: &str) -> Result<Self, Error>
Create an instance from a string literal in a value position.
Implementations on Foreign Types§
source§impl<T> FromMeta for Result<T, Meta>where
T: FromMeta,
impl<T> FromMeta for Result<T, Meta>where
T: FromMeta,
Parses the meta-item, and in case of error preserves a copy of the input for later analysis.
source§impl FromMeta for WhereClause
impl FromMeta for WhereClause
fn from_string(value: &str) -> Result<WhereClause, Error>
source§impl<V> FromMeta for HashMap<String, V, RandomState>where
V: FromMeta,
impl<V> FromMeta for HashMap<String, V, RandomState>where
V: FromMeta,
fn from_list(
nested: &[NestedMeta]
) -> Result<HashMap<String, V, RandomState>, Error>
source§impl FromMeta for Vec<WherePredicate, Global>
impl FromMeta for Vec<WherePredicate, Global>
fn from_string(value: &str) -> Result<Vec<WherePredicate, Global>, Error>
Implementors§
impl FromMeta for ForwardAttrs
impl FromMeta for DataShape
impl FromMeta for Shape
impl FromMeta for Flag
impl FromMeta for IdentList
impl FromMeta for IdentString
impl FromMeta for Ignored
impl<T> FromMeta for Override<T>where
T: FromMeta,
Parses a Meta
. A bare word will produce Override::Inherit
, while
any value will be forwarded to T::from_meta
.