Rope

Struct Rope 

Source
pub struct Rope<'a> { /* private fields */ }
Expand description

A rope data structure.

Implementations§

Source§

impl<'a> Rope<'a>

Source

pub const fn new() -> Self

Creates a new empty rope.

Source

pub fn add(&mut self, value: &'a str)

Adds a string slice to the end of the rope.

Converts from simple to complex representation on first add. Empty strings are ignored.

Source

pub fn append(&mut self, value: Rope<'a>)

Appends another rope to this rope.

Handles all combinations of simple and complex representations efficiently.

Source

pub fn byte(&self, byte_index: usize) -> u8

Gets the byte at the given index.

§Panics

When index is out of bounds.

Source

pub fn get_byte(&self, byte_index: usize) -> Option<u8>

Non-panicking version of Rope::byte.

Gets the byte at the given index, returning None if out of bounds.

Source

pub fn char_indices(&self) -> CharIndices<'_>

Returns an iterator over the characters and their byte positions.

Source

pub fn starts_with(&self, value: &Rope<'_>) -> bool

Returns whether the rope starts with the given string.

Source

pub fn ends_with(&self, value: char) -> bool

Returns whether the rope ends with the given string.

Source

pub fn is_empty(&self) -> bool

Returns whether the rope is empty.

Source

pub fn len(&self) -> usize

Returns the length of the rope in bytes.

Source

pub fn byte_slice<R>(&self, range: R) -> Rope<'a>
where R: RangeBounds<usize>,

Returns a slice of the rope in the given byte range.

§Panics
  • When start > end
  • When end is out of bounds
  • When indices are not on char boundaries
Source

pub fn get_byte_slice<R>(&self, range: R) -> Option<Rope<'a>>
where R: RangeBounds<usize>,

Non-panicking version of Rope::byte_slice.

Source

pub unsafe fn byte_slice_unchecked<R>(&self, range: R) -> Rope<'a>
where R: RangeBounds<usize>,

Range-unchecked version of Rope::byte_slice.

§Safety

This is not safe, due to the following invariants that must be upheld:

  • Range must be within bounds.
  • Range start must be less than or equal to the end.
  • Both range start and end must be on char boundaries.
Source

pub fn lines(&self) -> Lines<'_, 'a>

Returns an iterator over the lines of the rope.

Source

pub fn to_bytes(&self) -> Cow<'a, [u8]>

Converts the rope to bytes.

Returns borrowed bytes for simple ropes and owned bytes for complex ropes.

Trait Implementations§

Source§

impl<'a> Clone for Rope<'a>

Source§

fn clone(&self) -> Rope<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Rope<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Rope<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> From<&'a Cow<'a, str>> for Rope<'a>

Source§

fn from(value: &'a Cow<'a, str>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a String> for Rope<'a>

Source§

fn from(value: &'a String) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for Rope<'a>

Source§

fn from(value: &'a str) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromIterator<&'a str> for Rope<'a>

Source§

fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Rope<'_>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq<&str> for Rope<'_>

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Rope<'_>> for Rope<'_>

Source§

fn eq(&self, other: &Rope<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for Rope<'_>

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToString for Rope<'_>

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Rope<'a>

§

impl<'a> RefUnwindSafe for Rope<'a>

§

impl<'a> !Send for Rope<'a>

§

impl<'a> !Sync for Rope<'a>

§

impl<'a> Unpin for Rope<'a>

§

impl<'a> UnwindSafe for Rope<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.