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

The type this can be converted from

Required Methods

This takes Self::Type and converts it to Self.

This can return an error, e.g. when parsing an integer too large for a u8 into an u8

Provided Methods

Should values of this type return their default when they are not specified even when the default flag is not specified (only returns true for Option, Vec and bool currently)

The default value, this is necessary to implement the implicit default behavior of Option and bool.

This is necessary as the Default trait cannot be used in expanded code, but normally you can easily implement it using it:

impl ConvertParsed for bool {
    fn default() -> Self {
        Default::default()
    }
}

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.

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

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 ())

Implementors