pub struct ReplaceOptions {Show 14 fields
pub regex: bool,
pub nth: Option<usize>,
pub case_insensitive: bool,
pub multiline: bool,
pub insert_before: Option<String>,
pub insert_after: Option<String>,
pub whole_line: bool,
pub range: Option<(usize, Option<usize>)>,
pub if_exists: bool,
pub word_boundary: bool,
pub unique: bool,
pub fuzzy: bool,
pub before_context: Option<String>,
pub after_context: Option<String>,
}Expand description
Options for text replacement operations.
Fields§
§regex: boolUse regex mode for the from pattern.
nth: Option<usize>Replace only the Nth match (1-based). None means replace all.
case_insensitive: boolCase-insensitive matching.
multiline: boolEnable multiline matching (dot matches newlines in regex mode).
insert_before: Option<String>Text to insert before each match instead of replacing.
Mutually exclusive with to (the replacement text) and insert_after.
insert_after: Option<String>Text to insert after each match instead of replacing.
Mutually exclusive with to (the replacement text) and insert_before.
whole_line: boolDelete/replace entire lines containing the match rather than just the
matched text. When to is empty, matching lines are removed.
range: Option<(usize, Option<usize>)>Restrict matching to a 1-based inclusive line range (start, end).
Requires whole_line to be true.
if_exists: boolReturn success (no error) even when the pattern matches nothing.
word_boundary: boolWhen true, match only at word boundaries (\b in regex terms).
Prevents SetupFile from matching inside BenchSetupFile.
The pattern is auto-escaped for regex metacharacters before
wrapping with \b anchors.
unique: boolWhen true, the operation fails if the pattern matches more than once.
This enforces unambiguous edits: the caller is guaranteed that exactly one location was affected, or the operation is rejected with an error. Useful for AI coding agents that need to ensure each edit targets a unique location in the file.
fuzzy: boolWhen true and the exact match fails (0 matches), attempt fuzzy
resolution via resolve_with_fallback (anchor + similarity matching).
On fuzzy success, the matched text is used for the replacement.
On fuzzy failure, the error includes “did you mean?” suggestions.
Only applies to literal (non-regex) patterns.
before_context: Option<String>Context line(s) before the target for anchor-based fallback matching. When the pattern matches multiple times, the match nearest to this anchor text is selected.
after_context: Option<String>Context line(s) after the target for anchor-based fallback matching. When the pattern matches multiple times, the match nearest to this anchor text is selected.
Trait Implementations§
Source§impl Clone for ReplaceOptions
impl Clone for ReplaceOptions
Source§fn clone(&self) -> ReplaceOptions
fn clone(&self) -> ReplaceOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ReplaceOptions
impl Debug for ReplaceOptions
Source§impl Default for ReplaceOptions
impl Default for ReplaceOptions
Source§fn default() -> ReplaceOptions
fn default() -> ReplaceOptions
Auto Trait Implementations§
impl Freeze for ReplaceOptions
impl RefUnwindSafe for ReplaceOptions
impl Send for ReplaceOptions
impl Sync for ReplaceOptions
impl Unpin for ReplaceOptions
impl UnsafeUnpin for ReplaceOptions
impl UnwindSafe for ReplaceOptions
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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