Skip to main content

Rope

Struct Rope 

Source
pub struct Rope { /* private fields */ }
Expand description

An implementation of a rope data structure, composed of lines of owned strings. This is used to implement text controls in Servo.

Implementations§

Source§

impl Rope

Source

pub fn new(contents: impl Into<String>) -> Self

Source

pub fn contents(&self) -> String

Source

pub fn last_index(&self) -> RopeIndex

Source

pub fn replace_range( &mut self, range: Range<RopeIndex>, string: impl Into<String>, ) -> RopeIndex

Replace the given range of RopeIndexs with the given string. Returns the RopeIndex of the end of the insertion.

Source

pub fn slice<'a>( &'a self, start: Option<RopeIndex>, end: Option<RopeIndex>, ) -> RopeSlice<'a>

Create a RopeSlice for this Rope from start to end. If either of these is None, then the slice will extend to the extent of the rope.

Source

pub fn chars<'a>(&'a self) -> RopeChars<'a>

Source

pub fn is_empty(&self) -> bool

Return true if the Rope is empty or false otherwise. This will also return true if the contents of the Rope are a single empty line.

Source

pub fn len_utf16(&self) -> Utf16CodeUnitLength

The total number of code units required to encode the content in utf16.

Source

pub fn move_by( &self, origin: RopeIndex, unit: RopeMovement, amount: isize, ) -> RopeIndex

Source

pub fn normalize_index(&self, rope_index: RopeIndex) -> RopeIndex

Given a RopeIndex, clamp it and ensure that it is on a character boundary, meaning that its indices are all bound by the actual size of the line and the number of lines in this Rope.

Source

pub fn index_to_utf8_offset(&self, rope_index: RopeIndex) -> Utf8CodeUnitLength

Convert a RopeIndex into a byte offset from the start of the content.

Source

pub fn index_to_utf16_offset( &self, rope_index: RopeIndex, ) -> Utf16CodeUnitLength

Source

pub fn index_to_character_offset(&self, rope_index: RopeIndex) -> usize

Convert a RopeIndex into a character offset from the start of the content.

Source

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.

Source

pub fn utf16_offset_to_utf8_offset( &self, utf16_offset: Utf16CodeUnitLength, ) -> Utf8CodeUnitLength

Source

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.
Source

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

Source§

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 UnsafeUnpin for Rope

§

impl UnwindSafe for Rope

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T