Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ impl EcoString {
self.0.clear();
}

/// Shortens the string to the specified length.
///
/// If `new_len` is greater than or equal to the string's current length,
/// this has no effect.
///
/// Panics if `new_len` does not lie on a [`char`] boundary.
#[inline]
pub fn truncate(&mut self, new_len: usize) {
if new_len <= self.len() {
assert!(self.is_char_boundary(new_len));
self.0.truncate(new_len);
}
}

/// Replaces all matches of a string with another string.
///
/// This is a bit less general that [`str::replace`] because the `Pattern`
Expand Down