Struct rat_widget::text::core::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

source

pub fn rope_slice(&self, range: TextRange) -> Result<RopeSlice<'_>, TextError>

A range of the text as RopeSlice.

Trait Implementations§

source§

impl Clone for TextRope

source§

fn clone(&self) -> TextRope

Returns a copy 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 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.

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

The byte-range must be a valid range.

source§

fn graphemes( &self, range: TextRange, pos: TextPosition, ) -> Result<impl Iterator<Item = Grapheme<'_>> + Cursor, TextError>

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

  • range must be a valid range. row <= len_lines, col <= line_width of the row.
  • 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<impl Iterator<Item = Grapheme<'_>> + Cursor, 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§

fn len_lines(&self) -> u32

Number of lines.

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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> 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.