pub struct Pattern {
pub before_template: String,
pub after_template: String,
pub variables: Vec<PatternVar>,
pub language: String,
pub confidence: f64,
}Expand description
Represents an inferred transformation pattern.
A Pattern is the central data structure of the codemod engine. It captures
what to look for in source code (before_template) and what to replace
it with (after_template), using PatternVars as placeholders for
varying sub-expressions.
§Template syntax
Variables are written as $name inside the template strings. For example:
before: "println!($fmt, $arg)"
after: "log::info!($fmt, $arg)"Fields§
§before_template: StringThe “before” pattern template with $variable placeholders.
after_template: StringThe “after” pattern template with $variable placeholders.
variables: Vec<PatternVar>Variables extracted during inference.
language: StringThe source language identifier (e.g. "rust", "javascript").
confidence: f64Confidence score of the inference in the range [0.0, 1.0].
Higher values indicate that the inferred pattern is more likely to be correct and generalizable.
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn new(
before_template: String,
after_template: String,
variables: Vec<PatternVar>,
language: String,
confidence: f64,
) -> Self
pub fn new( before_template: String, after_template: String, variables: Vec<PatternVar>, language: String, confidence: f64, ) -> Self
Creates a new pattern with the given templates and variables.
Sourcepub fn has_variables(&self) -> bool
pub fn has_variables(&self) -> bool
Returns true if this pattern contains at least one variable.
Sourcepub fn meets_confidence(&self, threshold: f64) -> bool
pub fn meets_confidence(&self, threshold: f64) -> bool
Returns true if the confidence score meets the given threshold.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Pattern
impl<'de> Deserialize<'de> for Pattern
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Pattern
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnsafeUnpin for Pattern
impl UnwindSafe for Pattern
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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