Trait attribute_derive::ConvertParsed
source · pub trait ConvertParsedwhere
Self: Sized,
Self::Type: Error,{
type Type;
// Required method
fn convert(value: Self::Type) -> Result<Self>;
// Provided methods
fn default_by_default() -> bool { ... }
fn default() -> Self { ... }
fn as_flag() -> Option<Self::Type> { ... }
fn aggregate(
this: Option<IdentValue<Self::Type>>,
other: Option<IdentValue<Self::Type>>,
error_msg: &str
) -> Result<Option<IdentValue<Self::Type>>> { ... }
}
Expand description
Helper trait to convert syn types implementing Parse
like
LitStr
to rust types like String
You probably don’t need to implement this trait, as most syn types like
LitStr
and Type
or that have a direct equivalent in
those like String
, char
or f32
are already implemented. A
special treatment have Vecs
which are parsed using the helper
Array
with the syntax [a, b, c]
and Options
that will be
None
if not specified and Some
when the value is specified via the
attribute. It is not specified via Some(value)
but as just value
.
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn default_by_default() -> bool
fn default_by_default() -> bool
sourcefn as_flag() -> Option<Self::Type>
fn as_flag() -> Option<Self::Type>
Returns the value when this type is specified as flag i.e. just
#[attr(default)]
instead of #[attr(default=true)]
. This relies
on Self::default
.
sourcefn aggregate(
this: Option<IdentValue<Self::Type>>,
other: Option<IdentValue<Self::Type>>,
error_msg: &str
) -> Result<Option<IdentValue<Self::Type>>>
fn aggregate( this: Option<IdentValue<Self::Type>>, other: Option<IdentValue<Self::Type>>, error_msg: &str ) -> Result<Option<IdentValue<Self::Type>>>
Should values of this type be aggregated instead of conflict if specified multiple times
Currently this is only implemented for Arrays
Implementations on Foreign Types§
source§impl ConvertParsed for ExprIndex
impl ConvertParsed for ExprIndex
source§impl ConvertParsed for MetaNameValue
impl ConvertParsed for MetaNameValue
source§impl ConvertParsed for ExprLoop
impl ConvertParsed for ExprLoop
source§impl ConvertParsed for TypeGroup
impl ConvertParsed for TypeGroup
source§impl ConvertParsed for ExprReturn
impl ConvertParsed for ExprReturn
source§impl ConvertParsed for ExprBinary
impl ConvertParsed for ExprBinary
source§impl ConvertParsed for ExprClosure
impl ConvertParsed for ExprClosure
source§impl ConvertParsed for f32
impl ConvertParsed for f32
source§impl ConvertParsed for WhereClause
impl ConvertParsed for WhereClause
source§impl ConvertParsed for isize
impl ConvertParsed for isize
source§impl ConvertParsed for String
impl ConvertParsed for String
source§impl ConvertParsed for PercentEq
impl ConvertParsed for PercentEq
source§impl ConvertParsed for FieldsUnnamed
impl ConvertParsed for FieldsUnnamed
source§impl ConvertParsed for BareFnArg
impl ConvertParsed for BareFnArg
source§impl ConvertParsed for Underscore
impl ConvertParsed for Underscore
source§impl ConvertParsed for Visibility
impl ConvertParsed for Visibility
source§impl ConvertParsed for ExprYield
impl ConvertParsed for ExprYield
source§impl ConvertParsed for WherePredicate
impl ConvertParsed for WherePredicate
source§impl ConvertParsed for ExprContinue
impl ConvertParsed for ExprContinue
source§impl ConvertParsed for Continue
impl ConvertParsed for Continue
source§impl ConvertParsed for Constraint
impl ConvertParsed for Constraint
source§impl ConvertParsed for DotDotDot
impl ConvertParsed for DotDotDot
source§impl ConvertParsed for DotDotEq
impl ConvertParsed for DotDotEq
source§impl ConvertParsed for FieldsNamed
impl ConvertParsed for FieldsNamed
source§impl ConvertParsed for ExprMacro
impl ConvertParsed for ExprMacro
source§impl ConvertParsed for Override
impl ConvertParsed for Override
source§impl ConvertParsed for ExprTryBlock
impl ConvertParsed for ExprTryBlock
source§impl ConvertParsed for PathSegment
impl ConvertParsed for PathSegment
source§impl ConvertParsed for TypeTuple
impl ConvertParsed for TypeTuple
source§impl ConvertParsed for ExprUnary
impl ConvertParsed for ExprUnary
source§impl ConvertParsed for ExprAsync
impl ConvertParsed for ExprAsync
source§impl<Output, Parsed> ConvertParsed for Vec<Output>where
Output: ConvertParsed<Type = Parsed>,
Parsed: Clone,
impl<Output, Parsed> ConvertParsed for Vec<Output>where Output: ConvertParsed<Type = Parsed>, Parsed: Clone,
source§impl ConvertParsed for ExprRepeat
impl ConvertParsed for ExprRepeat
source§impl ConvertParsed for TypeMacro
impl ConvertParsed for TypeMacro
source§impl ConvertParsed for SelfValue
impl ConvertParsed for SelfValue
source§impl ConvertParsed for Abstract
impl ConvertParsed for Abstract
source§impl ConvertParsed for TypeTraitObject
impl ConvertParsed for TypeTraitObject
source§impl ConvertParsed for ExprForLoop
impl ConvertParsed for ExprForLoop
source§impl ConvertParsed for Generics
impl ConvertParsed for Generics
source§impl ConvertParsed for ExprRange
impl ConvertParsed for ExprRange
source§impl ConvertParsed for Question
impl ConvertParsed for Question
source§impl ConvertParsed for TypeReference
impl ConvertParsed for TypeReference
source§impl ConvertParsed for TypeNever
impl ConvertParsed for TypeNever
source§impl ConvertParsed for ExprArray
impl ConvertParsed for ExprArray
source§impl ConvertParsed for BoundLifetimes
impl ConvertParsed for BoundLifetimes
source§impl ConvertParsed for TypeInfer
impl ConvertParsed for TypeInfer
source§impl ConvertParsed for TypeBareFn
impl ConvertParsed for TypeBareFn
source§impl ConvertParsed for TypeParam
impl ConvertParsed for TypeParam
source§impl ConvertParsed for ExprStruct
impl ConvertParsed for ExprStruct
source§impl ConvertParsed for ExprAssign
impl ConvertParsed for ExprAssign
source§impl ConvertParsed for u128
impl ConvertParsed for u128
source§impl ConvertParsed for TypeSlice
impl ConvertParsed for TypeSlice
source§impl ConvertParsed for ExprUnsafe
impl ConvertParsed for ExprUnsafe
source§impl ConvertParsed for TypePath
impl ConvertParsed for TypePath
source§impl ConvertParsed for bool
impl ConvertParsed for bool
source§impl ConvertParsed for TokenTree
impl ConvertParsed for TokenTree
source§impl ConvertParsed for ExprWhile
impl ConvertParsed for ExprWhile
source§impl ConvertParsed for TypeImplTrait
impl ConvertParsed for TypeImplTrait
source§impl ConvertParsed for ConstParam
impl ConvertParsed for ConstParam
source§impl ConvertParsed for ExprBlock
impl ConvertParsed for ExprBlock
source§impl ConvertParsed for SelfType
impl ConvertParsed for SelfType
source§impl ConvertParsed for TypeArray
impl ConvertParsed for TypeArray
source§impl ConvertParsed for TraitBound
impl ConvertParsed for TraitBound
source§impl ConvertParsed for LitByteStr
impl ConvertParsed for LitByteStr
source§impl ConvertParsed for i128
impl ConvertParsed for i128
source§impl ConvertParsed for TraitBoundModifier
impl ConvertParsed for TraitBoundModifier
source§impl ConvertParsed for TypeParen
impl ConvertParsed for TypeParen
source§impl ConvertParsed for ExprMethodCall
impl ConvertParsed for ExprMethodCall
source§impl ConvertParsed for f64
impl ConvertParsed for f64
source§impl ConvertParsed for ExprParen
impl ConvertParsed for ExprParen
source§impl ConvertParsed for DeriveInput
impl ConvertParsed for DeriveInput
source§impl ConvertParsed for char
impl ConvertParsed for char
source§impl ConvertParsed for TokenStream
impl ConvertParsed for TokenStream
Try to avoid using this, as it will consume everything behind, so it needs to be defined as the last parameter.
In the future there might be something to allow better handling of this (maybe by putting it
into ()
)