Skip to main content

Document

Struct Document 

Source
pub struct Document { /* private fields */ }

Implementations§

Source§

impl Document

Source

pub fn new(text: &str) -> Self

Source

pub fn chunks(&self) -> impl Iterator<Item = &str> + '_

The text in order, in the rope’s pieces (for hashing without a copy).

Source

pub fn len(&self) -> ByteOffset

Length in bytes; also the offset of the end of the document.

Source

pub fn is_empty(&self) -> bool

Source

pub fn line_count(&self) -> usize

Number of lines. An empty document, or one ending in \n, still has a (possibly empty) last line.

Source

pub fn line_of(&self, pos: ByteOffset) -> usize

Line containing pos. A \n belongs to the line it ends.

Source

pub fn line_start(&self, line: usize) -> ByteOffset

Source

pub fn line_end(&self, line: usize) -> ByteOffset

End of the line’s content, excluding its \n.

Source

pub fn line_text(&self, line: usize) -> String

The line’s content, excluding its \n.

Source

pub fn slice(&self, range: Range<ByteOffset>) -> String

Source

pub fn is_char_boundary(&self, pos: ByteOffset) -> bool

Source

pub fn chunk_at(&self, pos: ByteOffset) -> (&str, ByteOffset)

The chunk of text containing pos and the offset at which it starts. At the end of the document this is the last chunk. Grapheme segmentation in position walks the rope with this.

Source

pub fn char_at(&self, pos: ByteOffset) -> Option<char>

The char starting at pos, if any.

Source

pub fn to_char_idx(&self, pos: ByteOffset) -> CharIdx

Source

pub fn replace(&mut self, range: Range<ByteOffset>, text: &str)

Replaces range with text. Both ends must be char boundaries.

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

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

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

impl Default for Document

Source§

fn default() -> Self

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

impl Display for Document

Source§

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

Formats the value using the given formatter. 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> 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> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.