Trait darling::FromMeta[][src]

pub trait FromMeta {
    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".

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 with Option. See darling::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>[src]

fn from_meta(item: &Meta) -> Result<Self, Error>[src]

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.

fn from_word() -> Result<Self, Error>[src]

Create an instance from the presence of the word in the attribute with no additional options specified.

fn from_list(items: &[NestedMeta]) -> Result<Self, Error>[src]

Create an instance from a list of nested meta items.

fn from_value(value: &Lit) -> Result<Self, Error>[src]

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.

fn from_char(value: char) -> Result<Self, Error>[src]

Create an instance from a char literal in a value position.

fn from_string(value: &str) -> Result<Self, Error>[src]

Create an instance from a string literal in a value position.

fn from_bool(value: bool) -> Result<Self, Error>[src]

Create an instance from a bool literal in a value position.

Implementations on Foreign Types

impl<T> FromMeta for Rc<T> where
    T: FromMeta
[src]

pub fn from_meta(item: &Meta) -> Result<Rc<T>, Error>[src]

impl FromMeta for LitByte[src]

pub fn from_value(value: &Lit) -> Result<LitByte, Error>[src]

impl FromMeta for isize[src]

pub fn from_string(s: &str) -> Result<isize, Error>[src]

pub fn from_value(value: &Lit) -> Result<isize, Error>[src]

impl FromMeta for Vec<u64, Global>[src]

Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]".

pub fn from_value(value: &Lit) -> Result<Vec<u64, Global>, Error>[src]

impl FromMeta for LitByteStr[src]

impl FromMeta for u8[src]

pub fn from_string(s: &str) -> Result<u8, Error>[src]

pub fn from_value(value: &Lit) -> Result<u8, Error>[src]

impl<V, S> FromMeta for HashMap<String, V, S> where
    V: FromMeta,
    S: BuildHasher + Default
[src]

impl<T> FromMeta for Result<T, Error> where
    T: FromMeta
[src]

pub fn from_meta(item: &Meta) -> Result<Result<T, Error>, Error>[src]

impl<T> FromMeta for Result<T, Meta> where
    T: FromMeta
[src]

Parses the meta-item, and in case of error preserves a copy of the input for later analysis.

pub fn from_meta(item: &Meta) -> Result<Result<T, Meta>, Error>[src]

impl FromMeta for i64[src]

pub fn from_string(s: &str) -> Result<i64, Error>[src]

pub fn from_value(value: &Lit) -> Result<i64, Error>[src]

impl FromMeta for Vec<u32, Global>[src]

Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]".

pub fn from_value(value: &Lit) -> Result<Vec<u32, Global>, Error>[src]

impl FromMeta for RenameRule[src]

pub fn from_string(value: &str) -> Result<RenameRule, Error>[src]

impl<V, S> FromMeta for HashMap<Ident, V, S> where
    V: FromMeta,
    S: BuildHasher + Default
[src]

impl FromMeta for ExprArray[src]

Parsing support for an array, i.e. example = "[1 + 2, 2 - 2, 3 * 4]".

impl FromMeta for Vec<u8, Global>[src]

Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]".

pub fn from_value(value: &Lit) -> Result<Vec<u8, Global>, Error>[src]

impl<T> FromMeta for RefCell<T> where
    T: FromMeta
[src]

pub fn from_meta(item: &Meta) -> Result<RefCell<T>, Error>[src]

impl FromMeta for LitInt[src]

pub fn from_value(value: &Lit) -> Result<LitInt, Error>[src]

impl FromMeta for Vec<u16, Global>[src]

Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]".

pub fn from_value(value: &Lit) -> Result<Vec<u16, Global>, Error>[src]

impl FromMeta for u32[src]

pub fn from_string(s: &str) -> Result<u32, Error>[src]

pub fn from_value(value: &Lit) -> Result<u32, Error>[src]

impl FromMeta for char[src]

pub fn from_char(value: char) -> Result<char, Error>[src]

pub fn from_string(s: &str) -> Result<char, Error>[src]

impl FromMeta for LitStr[src]

pub fn from_value(value: &Lit) -> Result<LitStr, Error>[src]

impl FromMeta for LitChar[src]

pub fn from_value(value: &Lit) -> Result<LitChar, Error>[src]

impl FromMeta for usize[src]

pub fn from_string(s: &str) -> Result<usize, Error>[src]

pub fn from_value(value: &Lit) -> Result<usize, Error>[src]

impl FromMeta for u64[src]

pub fn from_string(s: &str) -> Result<u64, Error>[src]

pub fn from_value(value: &Lit) -> Result<u64, Error>[src]

impl FromMeta for f32[src]

pub fn from_string(s: &str) -> Result<f32, Error>[src]

pub fn from_value(value: &Lit) -> Result<f32, Error>[src]

impl<T, P> FromMeta for Punctuated<T, P> where
    P: Parse,
    T: Parse
[src]

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.

pub fn from_value(value: &Lit) -> Result<Punctuated<T, P>, Error>[src]

impl FromMeta for i16[src]

pub fn from_string(s: &str) -> Result<i16, Error>[src]

pub fn from_value(value: &Lit) -> Result<i16, Error>[src]

impl<T> FromMeta for Box<T, Global> where
    T: FromMeta
[src]

pub fn from_meta(item: &Meta) -> Result<Box<T, Global>, Error>[src]

impl FromMeta for LitFloat[src]

pub fn from_value(value: &Lit) -> Result<LitFloat, Error>[src]

impl FromMeta for Meta[src]

pub fn from_meta(value: &Meta) -> Result<Meta, Error>[src]

impl FromMeta for Literal[src]

pub fn from_value(value: &Lit) -> Result<Literal, Error>[src]

impl FromMeta for String[src]

impl<V, S> FromMeta for HashMap<Path, V, S> where
    V: FromMeta,
    S: BuildHasher + Default
[src]

pub fn from_list(nested: &[NestedMeta]) -> Result<HashMap<Path, V, S>, Error>[src]

impl FromMeta for u16[src]

pub fn from_string(s: &str) -> Result<u16, Error>[src]

pub fn from_value(value: &Lit) -> Result<u16, Error>[src]

impl FromMeta for Vec<WherePredicate, Global>[src]

impl FromMeta for LitBool[src]

pub fn from_value(value: &Lit) -> Result<LitBool, Error>[src]

impl FromMeta for ()[src]

impl FromMeta for f64[src]

pub fn from_string(s: &str) -> Result<f64, Error>[src]

pub fn from_value(value: &Lit) -> Result<f64, Error>[src]

impl FromMeta for Path[src]

Parsing support for paths. This attempts to preserve span information when available, but also supports parsing strings with the call site as the emitted span.

pub fn from_string(value: &str) -> Result<Path, Error>[src]

pub fn from_value(value: &Lit) -> Result<Path, Error>[src]

impl FromMeta for Ident[src]

Parsing support for identifiers. This attempts to preserve span information when available, but also supports parsing strings with the call site as the emitted span.

pub fn from_string(value: &str) -> Result<Ident, Error>[src]

pub fn from_value(value: &Lit) -> Result<Ident, Error>[src]

impl<T> FromMeta for Option<T> where
    T: FromMeta
[src]

pub fn from_meta(item: &Meta) -> Result<Option<T>, Error>[src]

impl FromMeta for WhereClause[src]

impl FromMeta for i8[src]

pub fn from_string(s: &str) -> Result<i8, Error>[src]

pub fn from_value(value: &Lit) -> Result<i8, Error>[src]

impl<T> FromMeta for Arc<T> where
    T: FromMeta
[src]

pub fn from_meta(item: &Meta) -> Result<Arc<T>, Error>[src]

impl FromMeta for Vec<usize, Global>[src]

Parsing an unsigned integer array, i.e. example = "[1, 2, 3, 4]".

pub fn from_value(value: &Lit) -> Result<Vec<usize, Global>, Error>[src]

impl FromMeta for bool[src]

pub fn from_word() -> Result<bool, Error>[src]

pub fn from_bool(value: bool) -> Result<bool, Error>[src]

pub fn from_string(value: &str) -> Result<bool, Error>[src]

impl FromMeta for Lit[src]

pub fn from_value(value: &Lit) -> Result<Lit, Error>[src]

impl FromMeta for AtomicBool[src]

impl FromMeta for i32[src]

pub fn from_string(s: &str) -> Result<i32, Error>[src]

pub fn from_value(value: &Lit) -> Result<i32, Error>[src]

Implementors

impl FromMeta for Flag[src]

pub fn from_meta(mi: &Meta) -> Result<Flag, Error>[src]

impl FromMeta for IdentString[src]

impl FromMeta for Ignored[src]

impl FromMeta for PathList[src]

impl<T> FromMeta for Override<T> where
    T: FromMeta
[src]

Parses a Meta. A bare word will produce Override::Inherit, while any value will be forwarded to T::from_meta.

impl<T> FromMeta for SpannedValue<T> where
    T: FromMeta
[src]

pub fn from_meta(value: &Meta) -> Result<SpannedValue<T>, Error>[src]

impl<T> FromMeta for WithOriginal<T, Meta> where
    T: FromMeta
[src]

pub fn from_meta(value: &Meta) -> Result<WithOriginal<T, Meta>, Error>[src]