pub struct ReindentPlan<'a> { /* private fields */ }Expand description
Re-indents the replacement for each match of one find/replace (see
indentation_shift), sharing the work across matches. Finding which
replacement lines sit inside multi-line string literals needs a parse of
the edited file; a plan makes at most one such parse for all of its
matches, and only when some match needs shifting and a string delimiter
appears anywhere in the file, the matched lines or the replacement. A
replace_all over thousands of matches would otherwise parse the whole
file thousands of times.
Implementations§
Source§impl<'a> ReindentPlan<'a>
impl<'a> ReindentPlan<'a>
pub fn new( source: &'a str, needle: &'a str, replacement: &'a str, path: Option<&'a Path>, matches: &'a [FuzzyMatch], ) -> Self
pub fn source(&self) -> &'a str
pub fn matched(&self, index: usize) -> &'a FuzzyMatch
Sourcepub fn replacement_for(&self, index: usize) -> Result<Cow<'a, str>, AftError>
pub fn replacement_for(&self, index: usize) -> Result<Cow<'a, str>, AftError>
The replacement for the match at index, with every line moved by
the match’s indentation_shift. A loose match keeps the file’s
indentation for the matched lines, so writing newString as given
would leave every line after the first at oldString’s wrong
indentation: in Python that is an IndentationError or code moved into
another block. Lines inside a multi-line string literal are left
exactly as written (see Self::lines_inside_new_strings).
Auto Trait Implementations§
impl<'a> !Freeze for ReindentPlan<'a>
impl<'a> !RefUnwindSafe for ReindentPlan<'a>
impl<'a> !Sync for ReindentPlan<'a>
impl<'a> Forget for ReindentPlan<'a>
impl<'a> Move for ReindentPlan<'a>
impl<'a> Send for ReindentPlan<'a>
impl<'a> Unpin for ReindentPlan<'a>
impl<'a> UnsafeUnpin for ReindentPlan<'a>
impl<'a> UnwindSafe for ReindentPlan<'a>
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.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