pub struct PatternMatcher { /* private fields */ }Expand description
Finds occurrences of a Pattern in source code.
The matcher parses the source into an AST and then walks every subtree,
attempting to unify it with the before_template AST. When a subtree
matches — i.e. has the same structure and all non-variable leaves agree —
it records a Match with the captured variable bindings.
Implementations§
Source§impl PatternMatcher
impl PatternMatcher
Sourcepub fn new(language: Box<dyn LanguageAdapter>) -> Self
pub fn new(language: Box<dyn LanguageAdapter>) -> Self
Create a new matcher backed by the given language adapter.
Sourcepub fn find_matches(
&self,
source: &str,
pattern: &Pattern,
) -> Result<Vec<Match>>
pub fn find_matches( &self, source: &str, pattern: &Pattern, ) -> Result<Vec<Match>>
Find all matches of pattern in the given source code.
§Errors
Returns CodemodError::Parse if the source or the pattern template
cannot be parsed.
Auto Trait Implementations§
impl Freeze for PatternMatcher
impl !RefUnwindSafe for PatternMatcher
impl Send for PatternMatcher
impl Sync for PatternMatcher
impl Unpin for PatternMatcher
impl UnsafeUnpin for PatternMatcher
impl !UnwindSafe for PatternMatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more