pub struct Rope {
lines: Vec<String>,
}Expand description
An implementation of a rope data structure, composed of lines of owned strings. This is used to implement text controls in Servo.
Fields§
§lines: Vec<String>The lines of the rope. Each line is an owned string that ends with a newline
(\n), apart from the last line which has no trailing newline.
Implementations§
Source§impl Rope
impl Rope
pub fn new(contents: impl Into<String>) -> Self
pub fn contents(&self) -> String
pub fn last_index(&self) -> RopeIndex
Sourcepub fn replace_range(
&mut self,
range: Range<RopeIndex>,
string: impl Into<String>,
) -> RopeIndex
pub fn replace_range( &mut self, range: Range<RopeIndex>, string: impl Into<String>, ) -> RopeIndex
fn delete_range(&mut self, range: Range<RopeIndex>)
Sourcepub fn slice<'a>(
&'a self,
start: Option<RopeIndex>,
end: Option<RopeIndex>,
) -> RopeSlice<'a>
pub fn slice<'a>( &'a self, start: Option<RopeIndex>, end: Option<RopeIndex>, ) -> RopeSlice<'a>
pub fn chars<'a>(&'a self) -> RopeChars<'a> ⓘ
Sourcepub fn len_utf16(&self) -> Utf16CodeUnitLength
pub fn len_utf16(&self) -> Utf16CodeUnitLength
The total number of code units required to encode the content in utf16.
fn line(&self, index: usize) -> &str
fn line_for_index(&self, index: RopeIndex) -> &String
fn line_for_index_mut(&mut self, index: RopeIndex) -> &mut String
fn last_index_in_line(&self, line: usize) -> RopeIndex
Sourcefn start_of_following_line(&self, index: RopeIndex) -> RopeIndex
fn start_of_following_line(&self, index: RopeIndex) -> RopeIndex
Sourcefn end_of_preceding_line(&self, index: RopeIndex) -> RopeIndex
fn end_of_preceding_line(&self, index: RopeIndex) -> RopeIndex
pub fn move_by( &self, origin: RopeIndex, unit: RopeMovement, amount: isize, ) -> RopeIndex
fn move_by_lines(&self, origin: RopeIndex, lines_to_move: isize) -> RopeIndex
fn move_by_iterator( &self, origin: RopeIndex, unit: RopeMovement, amount: isize, ) -> RopeIndex
Sourcepub fn clamp_index(&self, rope_index: RopeIndex) -> RopeIndex
pub fn clamp_index(&self, rope_index: RopeIndex) -> RopeIndex
Sourcepub fn index_to_utf8_offset(&self, rope_index: RopeIndex) -> Utf8CodeUnitLength
pub fn index_to_utf8_offset(&self, rope_index: RopeIndex) -> Utf8CodeUnitLength
Convert a RopeIndex into a byte offset from the start of the content.
pub fn index_to_utf16_offset( &self, rope_index: RopeIndex, ) -> Utf16CodeUnitLength
Sourcepub fn utf8_offset_to_rope_index(
&self,
utf8_offset: Utf8CodeUnitLength,
) -> RopeIndex
pub fn utf8_offset_to_rope_index( &self, utf8_offset: Utf8CodeUnitLength, ) -> RopeIndex
Convert a byte offset from the start of the content into a RopeIndex.
pub fn utf16_offset_to_utf8_offset( &self, utf16_offset: Utf16CodeUnitLength, ) -> Utf8CodeUnitLength
Sourcepub fn relevant_word_boundaries<'a>(&'a self, index: RopeIndex) -> RopeSlice<'a>
pub fn relevant_word_boundaries<'a>(&'a self, index: RopeIndex) -> RopeSlice<'a>
Find the boundaries of the word most relevant to the given RopeIndex. Word
returned in order or precedence:
- If the index intersects the word or is the index directly preceding a word, the boundaries of that word are returned.
- The word preceding the cursor.
- If there is no word preceding the cursor, the start of the line to the end of the next word.
Sourcepub fn line_boundaries<'a>(&'a self, index: RopeIndex) -> RopeSlice<'a>
pub fn line_boundaries<'a>(&'a self, index: RopeIndex) -> RopeSlice<'a>
Return the boundaries of the line that contains the given RopeIndex.
Trait Implementations§
Source§impl MallocSizeOf for Rope
impl MallocSizeOf for Rope
Source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Measure the heap usage of all descendant heap-allocated structures, but
not the space taken up by the value itself.
Auto Trait Implementations§
impl Freeze for Rope
impl RefUnwindSafe for Rope
impl Send for Rope
impl Sync for Rope
impl Unpin for Rope
impl UnwindSafe for Rope
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> 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 moreSource§impl<T> MaybeBoxed<Box<T>> for T
impl<T> MaybeBoxed<Box<T>> for T
Source§fn maybe_boxed(self) -> Box<T>
fn maybe_boxed(self) -> Box<T>
Convert
Source§impl<T> MaybeBoxed<T> for T
impl<T> MaybeBoxed<T> for T
Source§fn maybe_boxed(self) -> T
fn maybe_boxed(self) -> T
Convert