Struct amplify_syn::SingularAttr[][src]

pub struct SingularAttr {
    pub name: String,
    pub value: ArgValue,
}
Expand description

Structure describing a procedural macro attribute with an optional value. The means that if one has something like #[name1], #[name2 = "value"], #[name3 = ::std::path::PathBuf)] than name1, name2 = "value", and name3 = ::std::path::PathBuf are three different attributes which can be parsed and represented by the SingularAttr structure.

NB: For #[attr(arg1, arg2 = value)] style of proc macros use ParametrizedAttr structure. If you need to support both use Attr enum.

Internally the structure is composed of the name and value fields, where name is always a syn::Ident (corresponding name1, name2, name3 from the sample above) and value is an optional literal Lit, with corresponding cases of None, Some(ArgValue::Literal(Lit::Str(LitStr))), and Some(ArgValue::Type(Type::Path(Path))).

Fields

name: String

Optional attribute argument path part; for instance in #[my(name = value)] or in #[name = value] this is a name part

value: ArgValue

Attribute argument value part; for instance in #[name = value] this is the value part

Implementations

Constructs named SingularAttr without value

Constructs SingularAttr from a vector of all syn-parsed attributes, selecting single attribute matching the provided name. If there are multiple instances of the same attribute, fails with Error::SingularAttrRequired

Constructs named SingularAttr setting its value to the provided literal

Constructs named SingularAttr setting its value to the provided rust type value

Constructs SingularAttr from a given syn::Attribute by parsing its data. Accepts only attributes having form #[attr(name = value)] and errors for other attribute types with Error::ArgNameMustBeIdent and Error::SingularAttrRequired

Returns literal value, if any, or fails with Error::ArgValueRequired. See ArgValue::literal_value for the details.

Returns type value, if any, or fails with Error::ArgValueRequired. See ArgValue::literal_value for the details.

Merges data from the other into the self.

Errors

Does merging as in SingularAttr::merge, but unlike it consumes the self and returns a merged structure in case of the successful operation. Useful in operation chains.

Enriches current attribute data by adding information from the provided syn::Attribute.

Errors

Performs enrich operation as in SingularAttr::enrich, but unlike it consumes the self and returns an enriched structure in case of the successful operation. Useful in operation chains.

Checks that the structure meets provided value requirements (see ArgValueReq), generating Error if the requirements are not met.

Performs check as in SingularAttr::check, but unlike it consumes the self and returns a itself in case of the successful operation. Useful in operation chains.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.