Skip to main content

MatcherExt

Trait MatcherExt 

Source
pub trait MatcherExt: Matcher {
    // Required methods
    fn match_node<'tree, D: Doc>(
        &self,
        node: Node<'tree, D>,
    ) -> Option<NodeMatch<'tree, D>>;
    fn find_node<'tree, D: Doc>(
        &self,
        node: Node<'tree, D>,
    ) -> Option<NodeMatch<'tree, D>>;
}
Expand description

Extension trait providing convenient utility methods for Matcher implementations.

Automatically implemented for all types that implement Matcher. Provides higher-level operations like finding nodes and working with meta-variable environments.

§Important

You should not implement this trait manually - it’s automatically implemented for all Matcher types.

§Example

let ast = Language::Tsx.ast_grep("const x = 42;");
let root = ast.root();

// Use MatcherExt methods
if let Some(node_match) = root.find("const $VAR = $VALUE") {
    println!("Found constant declaration");
}

Required Methods§

Source

fn match_node<'tree, D: Doc>( &self, node: Node<'tree, D>, ) -> Option<NodeMatch<'tree, D>>

Source

fn find_node<'tree, D: Doc>( &self, node: Node<'tree, D>, ) -> Option<NodeMatch<'tree, D>>

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<T> MatcherExt for T
where T: Matcher,