Trait attribute_derive::ConvertParsed
source · [−]pub trait ConvertParsed where
Self: Sized,
Self::Type: Error, {
type Type;
fn convert(value: Self::Type) -> Result<Self>;
fn default_by_default() -> bool { ... }
fn default() -> Self { ... }
fn as_flag() -> Option<Self::Type> { ... }
fn aggregate(
this: Option<Self::Type>,
other: Option<Self::Type>,
error1: &str,
error2: &str
) -> Result<Option<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
fn default_by_default() -> bool
fn default_by_default() -> bool
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
.
Implementations on Foreign Types
sourceimpl<Output, Parsed> ConvertParsed for Option<Output> where
Output: ConvertParsed<Type = Parsed>,
Parsed: Error + Clone,
impl<Output, Parsed> ConvertParsed for Option<Output> where
Output: ConvertParsed<Type = Parsed>,
Parsed: Error + Clone,
sourceimpl<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,
sourceimpl ConvertParsed for bool
impl ConvertParsed for bool
sourceimpl ConvertParsed for LitByteStr
impl ConvertParsed for LitByteStr
type Type = LitByteStr
fn convert(s: Self) -> Result<Self>
sourceimpl ConvertParsed for TokenTree
impl ConvertParsed for TokenTree
sourceimpl 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 ()
)