TextRope

Struct TextRope 

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

Text store with a rope.

Implementations§

Source§

impl TextRope

Source

pub fn new() -> TextRope

New empty.

Source

pub fn new_text(t: &str) -> TextRope

New from string.

Source

pub fn new_rope(r: Rope) -> TextRope

New from rope.

Source

pub fn rope(&self) -> &Rope

Borrow the rope

Trait Implementations§

Source§

impl Clone for TextRope

Source§

fn clone(&self) -> TextRope

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 Debug for TextRope

Source§

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

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

impl Default for TextRope

Source§

fn default() -> TextRope

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

impl TextStore for TextRope

Source§

fn is_multi_line(&self) -> bool

Can store multi-line content?

If this returns false it is an error to call any function with a row other than 0.

Source§

fn cache_validity(&self) -> Option<usize>

Minimum byte position that has been changed since the last call of min_changed().

Used to invalidate caches.

Source§

fn string(&self) -> String

Content as string.

Source§

fn set_string(&mut self, t: &str)

Set content.

Source§

fn byte_range_at(&self, pos: TextPosition) -> Result<Range<usize>, TextError>

Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.

  • pos must be a valid position: row <= len_lines, col <= line_width of the row.
Source§

fn byte_range(&self, range: TextRange) -> Result<Range<usize>, TextError>

Grapheme range to byte range.

  • range must be a valid range. row <= len_lines, col <= line_width of the row.
Source§

fn byte_to_pos(&self, byte_pos: usize) -> Result<TextPosition, TextError>

Byte position to grapheme position. Returns the position that contains the given byte index.

  • byte must <= byte-len.
Source§

fn bytes_to_range(&self, bytes: Range<usize>) -> Result<TextRange, TextError>

Byte range to grapheme range.

  • byte must <= byte-len.
Source§

fn str_slice(&self, range: TextRange) -> Result<Cow<'_, str>, TextError>

A range of the text as Cow<str>.

  • range must be a valid range. row <= len_lines, col <= line_width of the row.
  • pos must be inside of range.
Source§

fn str_slice_byte(&self, range: Range<usize>) -> Result<Cow<'_, str>, TextError>

A range of the text as Cow<str>.

The byte-range must be a valid range.

Source§

fn graphemes_byte( &self, range: Range<usize>, pos: usize, ) -> Result<<TextRope as TextStore>::GraphemeIter<'_>, TextError>

Return a cursor over the graphemes of the range, start at the given position.

  • range must be a valid byte-range.
  • pos must be inside of range.
Source§

fn line_at(&self, row: u32) -> Result<Cow<'_, str>, TextError>

Line as str.

  • row must be <= len_lines
Source§

fn lines_at( &self, row: u32, ) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>

Iterate over text-lines, starting at line-offset.

  • row must be <= len_lines
Source§

fn line_graphemes( &self, row: u32, ) -> Result<<TextRope as TextStore>::GraphemeIter<'_>, TextError>

Return a line as an iterator over the graphemes. This contains the ‘\n’ at the end.

  • row must be <= len_lines
Source§

fn line_width(&self, row: u32) -> Result<u32, TextError>

Line width as grapheme count. Excludes the terminating ‘\n’.

  • row must be <= len_lines
Source§

fn insert_char( &mut self, pos: TextPosition, ch: char, ) -> Result<(TextRange, Range<usize>), TextError>

Insert a char at the given position.

  • range must be a valid range. row <= len_lines, col <= line_width of the row.
Source§

fn insert_str( &mut self, pos: TextPosition, txt: &str, ) -> Result<(TextRange, Range<usize>), TextError>

Insert a text str at the given position.

  • range must be a valid range. row <= len_lines, col <= line_width of the row.
Source§

fn remove( &mut self, range: TextRange, ) -> Result<(String, (TextRange, Range<usize>)), TextError>

Remove the given text range.

  • range must be a valid range. row <= len_lines, col <= line_width of the row.
Source§

fn insert_b(&mut self, byte_pos: usize, t: &str) -> Result<(), TextError>

Insert a string at the given byte index. Call this only for undo.

byte_pos must be <= len bytes.

Source§

fn remove_b(&mut self, byte_range: Range<usize>) -> Result<(), TextError>

Remove the given byte-range. Call this only for undo.

byte_pos must be <= len bytes.

Source§

type GraphemeIter<'a> = RopeGraphemes<'a>

Source§

fn has_final_newline(&self) -> bool

Is there a line-break at the end of the text?
Source§

fn len_bytes(&self) -> usize

Length in bytes
Source§

fn len_lines(&self) -> u32

Number of lines. Read more

Auto Trait Implementations§

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.