attribute_derive::parsing

Trait AttributeValue

Source
pub trait AttributeValue: AttributeBase {
    const EXPECTED: &'static str = "expected `=` or `(`";
    const PREFERRED_OPEN_DELIMITER: &'static str = " = ";
    const PREFERRED_CLOSE_DELIMITER: &'static str = "";

    // Required method
    fn parse_value(
        input: ParseStream<'_>,
    ) -> Result<SpannedValue<Self::Partial>>;

    // Provided methods
    fn parse_value_meta(
        input: ParseStream<'_>,
    ) -> Result<SpannedValue<Self::Partial>> { ... }
    fn parse_value_eq(
        input: ParseStream<'_>,
    ) -> Result<SpannedValue<Self::Partial>> { ... }
}
Expand description

Any values that can be parsed in an attribute input.

This is probably the trait you want to implement when you created a custom type for field inside #[derive(FromAttr)], as it will provide implementations for FromAttr, AttributeNamed and, if you implement the marker trait PositionalValue, AttributePositional as well.

For named attributes by default it will support both <name> = <value> and <function>(<like>), though this can be tweaked in the implementation.

Provided Associated Constants§

Source

const EXPECTED: &'static str = "expected `=` or `(`"

Printed when not encountering a ( or = respectively while trying to parse a AttributeNamed.

Source

const PREFERRED_OPEN_DELIMITER: &'static str = " = "

What open delimiter to use when providing error messages.

For <name> = <value>, this is " = ", for <function>(<like>), it is "(".

As named attributes can allow both <name> = <value> and name(<value>), this might not be the only way this attribute can be used.

Source

const PREFERRED_CLOSE_DELIMITER: &'static str = ""

What close delimiter to use when providing error messages.

For <name> = <value>, this is "", for <function>(<like>), it is ")".

As named attributes can allow both <name> = <value> and <name>(<value>), this might not be the only way this attribute can be used.

Required Methods§

Source

fn parse_value(input: ParseStream<'_>) -> Result<SpannedValue<Self::Partial>>

Parses the plain attribute value without leading = or enclosing parenthesis.

Note: this input includes potentially a trailing , and following arguments.

attribute = value, ...
            ^^^^^^^^^^

For simple syntax this is the only function needed to implement, as the default implementations for parse_value_meta and parse_value_eq.

Provided Methods§

Source

fn parse_value_meta( input: ParseStream<'_>, ) -> Result<SpannedValue<Self::Partial>>

Parses the attribute value when parentheses (() were peeked.

Note: this is the input with the parentheses, and potentially following arguments.

attribute(value), ...
         ^^^^^^^^^^^^

In the default implementation this calls through to parse_value after removing the parentheses.

Source

fn parse_value_eq(input: ParseStream<'_>) -> Result<SpannedValue<Self::Partial>>

Parses the attribute value when an equals (=) was peeked.

Note: this is the input with the equals, and potentially following arguments.

attribute = value, ...
          ^^^^^^^^^^^^

In the default implementation this calls through to parse_value after removing the =.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl AttributeValue for TokenTree

Source§

impl AttributeValue for Meta

Source§

impl AttributeValue for Expr

Source§

impl AttributeValue for Member

Source§

impl AttributeValue for GenericParam

Source§

impl AttributeValue for TraitBoundModifier

Source§

impl AttributeValue for TypeParamBound

Source§

impl AttributeValue for WherePredicate

Source§

impl AttributeValue for Lit

Source§

impl AttributeValue for BinOp

Source§

impl AttributeValue for UnOp

Source§

impl AttributeValue for GenericArgument

Source§

impl AttributeValue for Visibility

Source§

impl AttributeValue for ReturnType

Source§

impl AttributeValue for Type

Source§

impl AttributeValue for char

Source§

impl AttributeValue for f32

Source§

impl AttributeValue for f64

Source§

impl AttributeValue for i8

Source§

impl AttributeValue for i16

Source§

impl AttributeValue for i32

Source§

impl AttributeValue for i64

Source§

impl AttributeValue for i128

Source§

impl AttributeValue for isize

Source§

impl AttributeValue for u8

Source§

impl AttributeValue for u16

Source§

impl AttributeValue for u32

Source§

impl AttributeValue for u64

Source§

impl AttributeValue for u128

Source§

impl AttributeValue for usize

Source§

impl AttributeValue for String

Source§

impl AttributeValue for Group

Source§

impl AttributeValue for Ident

Source§

impl AttributeValue for Literal

Source§

impl AttributeValue for Punct

Source§

impl AttributeValue for MetaList

Source§

impl AttributeValue for MetaNameValue

Source§

impl AttributeValue for FieldsNamed

Source§

impl AttributeValue for FieldsUnnamed

Source§

impl AttributeValue for Variant

Source§

impl AttributeValue for DeriveInput

Source§

impl AttributeValue for Index

Source§

impl AttributeValue for BoundLifetimes

Source§

impl AttributeValue for ConstParam

Source§

impl AttributeValue for Generics

Source§

impl AttributeValue for TraitBound

Source§

impl AttributeValue for TypeParam

Source§

impl AttributeValue for WhereClause

Source§

impl AttributeValue for Lifetime

Source§

impl AttributeValue for LitBool

Source§

impl AttributeValue for LitByteStr

Source§

impl AttributeValue for LitChar

Source§

impl AttributeValue for LitFloat

Source§

impl AttributeValue for LitInt

Source§

impl AttributeValue for LitStr

Source§

impl AttributeValue for Macro

Source§

impl AttributeValue for AngleBracketedGenericArguments

Source§

impl AttributeValue for ParenthesizedGenericArguments

Source§

impl AttributeValue for Path

Source§

impl AttributeValue for PathSegment

Source§

impl AttributeValue for Abstract

Source§

impl AttributeValue for And

Source§

impl AttributeValue for AndAnd

Source§

impl AttributeValue for AndEq

Source§

impl AttributeValue for As

Source§

impl AttributeValue for Async

Source§

impl AttributeValue for At

Source§

impl AttributeValue for Auto

Source§

impl AttributeValue for Await

Source§

impl AttributeValue for Become

Source§

impl AttributeValue for Box

Source§

impl AttributeValue for Break

Source§

impl AttributeValue for Caret

Source§

impl AttributeValue for CaretEq

Source§

impl AttributeValue for Colon

Source§

impl AttributeValue for Comma

Source§

impl AttributeValue for Const

Source§

impl AttributeValue for Continue

Source§

impl AttributeValue for Crate

Source§

impl AttributeValue for Default

Source§

impl AttributeValue for Do

Source§

impl AttributeValue for Dollar

Source§

impl AttributeValue for Dot

Source§

impl AttributeValue for DotDot

Source§

impl AttributeValue for DotDotDot

Source§

impl AttributeValue for DotDotEq

Source§

impl AttributeValue for Dyn

Source§

impl AttributeValue for Else

Source§

impl AttributeValue for Enum

Source§

impl AttributeValue for Eq

Source§

impl AttributeValue for EqEq

Source§

impl AttributeValue for Extern

Source§

impl AttributeValue for FatArrow

Source§

impl AttributeValue for Final

Source§

impl AttributeValue for Fn

Source§

impl AttributeValue for For

Source§

impl AttributeValue for Ge

Source§

impl AttributeValue for Gt

Source§

impl AttributeValue for If

Source§

impl AttributeValue for Impl

Source§

impl AttributeValue for In

Source§

impl AttributeValue for LArrow

Source§

impl AttributeValue for Le

Source§

impl AttributeValue for Let

Source§

impl AttributeValue for Loop

Source§

impl AttributeValue for Lt

Source§

impl AttributeValue for Macro

Source§

impl AttributeValue for Match

Source§

impl AttributeValue for Minus

Source§

impl AttributeValue for MinusEq

Source§

impl AttributeValue for Mod

Source§

impl AttributeValue for Move

Source§

impl AttributeValue for Mut

Source§

impl AttributeValue for Ne

Source§

impl AttributeValue for Not

Source§

impl AttributeValue for Or

Source§

impl AttributeValue for OrEq

Source§

impl AttributeValue for OrOr

Source§

impl AttributeValue for Override

Source§

impl AttributeValue for PathSep

Source§

impl AttributeValue for Percent

Source§

impl AttributeValue for PercentEq

Source§

impl AttributeValue for Plus

Source§

impl AttributeValue for PlusEq

Source§

impl AttributeValue for Pound

Source§

impl AttributeValue for Priv

Source§

impl AttributeValue for Pub

Source§

impl AttributeValue for Question

Source§

impl AttributeValue for RArrow

Source§

impl AttributeValue for Ref

Source§

impl AttributeValue for Return

Source§

impl AttributeValue for SelfType

Source§

impl AttributeValue for SelfValue

Source§

impl AttributeValue for Semi

Source§

impl AttributeValue for Shl

Source§

impl AttributeValue for ShlEq

Source§

impl AttributeValue for Shr

Source§

impl AttributeValue for ShrEq

Source§

impl AttributeValue for Slash

Source§

impl AttributeValue for SlashEq

Source§

impl AttributeValue for Star

Source§

impl AttributeValue for StarEq

Source§

impl AttributeValue for Static

Source§

impl AttributeValue for Struct

Source§

impl AttributeValue for Super

Source§

impl AttributeValue for Tilde

Source§

impl AttributeValue for Trait

Source§

impl AttributeValue for Try

Source§

impl AttributeValue for Type

Source§

impl AttributeValue for Typeof

Source§

impl AttributeValue for Underscore

Source§

impl AttributeValue for Union

Source§

impl AttributeValue for Unsafe

Source§

impl AttributeValue for Unsized

Source§

impl AttributeValue for Use

Source§

impl AttributeValue for Virtual

Source§

impl AttributeValue for Where

Source§

impl AttributeValue for While

Source§

impl AttributeValue for Yield

Source§

impl AttributeValue for Abi

Source§

impl AttributeValue for BareFnArg

Source§

impl AttributeValue for TypeArray

Source§

impl AttributeValue for TypeBareFn

Source§

impl AttributeValue for TypeGroup

Source§

impl AttributeValue for TypeImplTrait

Source§

impl AttributeValue for TypeInfer

Source§

impl AttributeValue for TypeMacro

Source§

impl AttributeValue for TypeNever

Source§

impl AttributeValue for TypeParen

Source§

impl AttributeValue for TypePath

Source§

impl AttributeValue for TypePtr

Source§

impl AttributeValue for TypeReference

Source§

impl AttributeValue for TypeSlice

Source§

impl AttributeValue for TypeTraitObject

Source§

impl AttributeValue for TypeTuple

Source§

impl<T: AttributePositional> AttributeValue for Vec<T>

Implementors§

Source§

impl<T: AttributeMeta> AttributeValue for T

Source§

const EXPECTED: &'static str = "expected `(`"

Source§

const PREFERRED_CLOSE_DELIMITER: &'static str = ")"

Source§

const PREFERRED_OPEN_DELIMITER: &'static str = "("