paralegal_flow::utils

Trait MetaItemMatch

Source
pub trait MetaItemMatch {
    // Required method
    fn match_get_ref(&self, path: &[Symbol]) -> Option<&AttrArgs>;

    // Provided methods
    fn match_extract<A, F: Fn(&AttrArgs) -> A>(
        &self,
        path: &[Symbol],
        parse: F,
    ) -> Option<A> { ... }
    fn matches_path(&self, path: &[Symbol]) -> bool { ... }
}
Expand description

This is meant as an extension trait for ast::Attribute. The main method of interest is match_extract, matches_path is interesting if you want to check if this attribute has the path of interest but you do not care about its payload.

Required Methods§

Source

fn match_get_ref(&self, path: &[Symbol]) -> Option<&AttrArgs>

Provided Methods§

Source

fn match_extract<A, F: Fn(&AttrArgs) -> A>( &self, path: &[Symbol], parse: F, ) -> Option<A>

If the provided symbol path matches the path segments in the attribute exactly then this method applies the parse function and returns the results of parsing. Otherwise returns None.

In pseudo-rust terms this would mean

(#[foo::bar(baz)]   ).match_extract(&sym_vec!["foo", "bar"], |a| a) == Some(baz)
(#[foo(bar)]        ).match_extract(&sym_vec!["foo", "bar"], |a| a) == None
(#[foo::bar::baz(x)]).match_extract(&sym_vec!["foo", "bar"], |a| a) == None

The [crate::ann_parse] module contains a parser combinator framework suitable for implementing parse. For examples on how to run the functions see the source for match_exception or ann_match_fn.

Source

fn matches_path(&self, path: &[Symbol]) -> bool

Check that this attribute matches the provided path. All attribute payload is ignored (i.e. no error if there is a payload).

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.

Implementations on Foreign Types§

Source§

impl MetaItemMatch for Attribute

Source§

fn match_get_ref(&self, path: &[Symbol]) -> Option<&AttrArgs>

Implementors§