Trait AttributeParser

Source
pub(crate) trait AttributeParser: Default + 'static {
    const ATTRIBUTES: &'static [(&'static [Symbol], fn(&mut Self, &AcceptContext<'_>, &ArgParser<'_>))];

    // Required method
    fn finalize(self, cx: &FinalizeContext<'_>) -> Option<AttributeKind>;
}
Expand description

An AttributeParser is a type which searches for syntactic attributes.

Parsers are often tiny state machines that gets to see all syntactical attributes on an item. Default::default creates a fresh instance that sits in some kind of initial state, usually that the attribute it is looking for was not yet seen.

Then, it defines what paths this group will accept in AttributeParser::ATTRIBUTES. These are listed as pairs, of symbols and function pointers. The function pointer will be called when that attribute is found on an item, which can influence the state of the little state machine.

Finally, after all attributes on an item have been seen, and possibly been accepted, the finalize functions for all attribute parsers are called. Each can then report whether it has seen the attribute it has been looking for.

The state machine is automatically reset to parse attributes on the next item.

Required Associated Constants§

Source

const ATTRIBUTES: &'static [(&'static [Symbol], fn(&mut Self, &AcceptContext<'_>, &ArgParser<'_>))]

The symbols for the attributes that this parser is interested in.

If an attribute has this symbol, the accept function will be called on it.

Required Methods§

Source

fn finalize(self, cx: &FinalizeContext<'_>) -> Option<AttributeKind>

The parser has gotten a chance to accept the attributes on an item, here it can produce an attribute.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl AttributeParser for ConfusablesParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], fn(&mut Self, &AcceptContext<'_>, &ArgParser<'_>))]

Source§

impl AttributeParser for BodyStabilityParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], fn(&mut Self, &AcceptContext<'_>, &ArgParser<'_>))]

Source§

impl AttributeParser for ConstStabilityParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], fn(&mut Self, &AcceptContext<'_>, &ArgParser<'_>))]

Source§

impl AttributeParser for StabilityParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], fn(&mut Self, &AcceptContext<'_>, &ArgParser<'_>))]

Source§

impl<T: CombineAttributeParser> AttributeParser for Combine<T>

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], fn(&mut Self, &AcceptContext<'_>, &ArgParser<'_>))]

Source§

impl<T: SingleAttributeParser> AttributeParser for Single<T>

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], fn(&mut Self, &AcceptContext<'_>, &ArgParser<'_>))]