Trait attribute_derive::parsing::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 =.

Object Safety§

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 = "("