pub struct MagicString<'s> { /* private fields */ }Implementations§
Source§impl<'text> MagicString<'text>
impl<'text> MagicString<'text>
pub fn append(&mut self, source: impl Into<Cow<'text, str>>) -> &mut Self
Sourcepub fn append_left(
&mut self,
text_index: usize,
content: impl Into<Cow<'text, str>>,
) -> &mut Self
pub fn append_left( &mut self, text_index: usize, content: impl Into<Cow<'text, str>>, ) -> &mut Self
§Example
use string_wizard::MagicString;
let mut s = MagicString::new("01234");
s.append_left(2, "a");
s.append_left(2, "b");
assert_eq!(s.to_string(), "01ab234")Sourcepub fn append_right(
&mut self,
text_index: usize,
content: impl Into<Cow<'text, str>>,
) -> &mut Self
pub fn append_right( &mut self, text_index: usize, content: impl Into<Cow<'text, str>>, ) -> &mut Self
§Example
use string_wizard::MagicString;
let mut s = MagicString::new("01234");
s.append_right(2, "A");
s.append_right(2, "B");
s.append_left(2, "a");
s.append_left(2, "b");
assert_eq!(s.to_string(), "01abAB234")Source§impl MagicString<'_>
impl MagicString<'_>
pub fn indent(&mut self) -> &mut Self
pub fn indent_with(&mut self, opts: IndentOptions<'_, '_>) -> &mut Self
Source§impl MagicString<'_>
impl MagicString<'_>
Source§impl<'text> MagicString<'text>
impl<'text> MagicString<'text>
Source§impl<'text> MagicString<'text>
impl<'text> MagicString<'text>
pub fn replace( &mut self, from: &str, to: impl Into<Cow<'text, str>>, ) -> Result<&mut Self, String>
pub fn replace_all( &mut self, from: &str, to: impl Into<Cow<'text, str>>, ) -> Result<&mut Self, String>
pub fn replace_with( &mut self, from: &str, to: impl Into<Cow<'text, str>>, options: ReplaceOptions, ) -> Result<&mut Self, String>
Source§impl<'text> MagicString<'text>
impl<'text> MagicString<'text>
Sourcepub fn reset(&mut self, start: usize, end: usize) -> Result<&mut Self, String>
pub fn reset(&mut self, start: usize, end: usize) -> Result<&mut Self, String>
Resets the portion of the string from start to end to its original content.
This undoes any modifications (updates, overwrites, intro/outro additions) made to that range.
§Errors
- If
startis greater than toend - If the range is out of bounds
Source§impl<'text> MagicString<'text>
impl<'text> MagicString<'text>
Source§impl MagicString<'_>
impl MagicString<'_>
pub fn source_map(&self, opts: SourceMapOptions) -> SourceMap
Source§impl<'text> MagicString<'text>
impl<'text> MagicString<'text>
Sourcepub fn trim(&mut self, char_type: Option<&str>) -> &mut Self
pub fn trim(&mut self, char_type: Option<&str>) -> &mut Self
Trims whitespace from the start and end of the string.
Sourcepub fn trim_start(&mut self, char_type: Option<&str>) -> &mut Self
pub fn trim_start(&mut self, char_type: Option<&str>) -> &mut Self
Trims whitespace from the start of the string.
Sourcepub fn trim_end(&mut self, char_type: Option<&str>) -> &mut Self
pub fn trim_end(&mut self, char_type: Option<&str>) -> &mut Self
Trims whitespace from the end of the string.
Sourcepub fn trim_lines(&mut self) -> &mut Self
pub fn trim_lines(&mut self) -> &mut Self
Trims newlines from the start and end of the string.
Source§impl<'text> MagicString<'text>
impl<'text> MagicString<'text>
Sourcepub fn update(
&mut self,
start: usize,
end: usize,
content: impl Into<Cow<'text, str>>,
) -> Result<&mut Self, String>
pub fn update( &mut self, start: usize, end: usize, content: impl Into<Cow<'text, str>>, ) -> Result<&mut Self, String>
A shorthand for update_with(start, end, content, Default::default());
pub fn update_with( &mut self, start: usize, end: usize, content: impl Into<Cow<'text, str>>, opts: UpdateOptions, ) -> Result<&mut Self, String>
Source§impl<'text> MagicString<'text>
impl<'text> MagicString<'text>
pub fn new(source: impl Into<Cow<'text, str>>) -> Self
pub fn with_options( source: impl Into<Cow<'text, str>>, options: MagicStringOptions, ) -> Self
pub fn source(&self) -> &str
pub fn filename(&self) -> Option<&str>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn has_changed(&self) -> bool
pub fn has_changed(&self) -> bool
Indicates if the string has been changed.
Trait Implementations§
Source§impl<'s> Clone for MagicString<'s>
impl<'s> Clone for MagicString<'s>
Source§fn clone(&self) -> MagicString<'s>
fn clone(&self) -> MagicString<'s>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'s> Debug for MagicString<'s>
impl<'s> Debug for MagicString<'s>
Source§impl Default for MagicString<'_>
impl Default for MagicString<'_>
Auto Trait Implementations§
impl<'s> !Freeze for MagicString<'s>
impl<'s> RefUnwindSafe for MagicString<'s>
impl<'s> Send for MagicString<'s>
impl<'s> Sync for MagicString<'s>
impl<'s> Unpin for MagicString<'s>
impl<'s> UnwindSafe for MagicString<'s>
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> 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>
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