Struct Selectionless

Source
pub struct Selectionless(/* private fields */);
Expand description

A Text that is guaranteed not to have Selections in it

Useful for sending across threads, especially when it comes to Logs.

Implementations§

Source§

impl Selectionless

Source

pub fn get(&self) -> Text

Gets the Text within, allowing for mutation again

Methods from Deref<Target = Text>§

Source

pub fn len(&self) -> Point

The Point at the end of the text

Source

pub fn is_empty(&self) -> bool

Whether or not there are any characters in the Text

This ignores the last '\n' in the Text, since it is always there no matter what.

This does not check for tags, so with a Ghost, there could actually be a “string” of characters on the Text, it just wouldn’t be considered real “text”. If you want to make sure it is indeed empty, see is_empty_empty.

Source

pub fn is_empty_empty(&self) -> bool

Whether the Bytes and Tags are empty

This ignores the last '\n' in the Text, since it is always there no matter what.

If you only want to check for the Bytes, ignoring possible Ghosts, see is_empty.

Source

pub fn char_at(&self, point: Point) -> Option<char>

The char at the Point’s position

Source

pub fn buffers(&self, range: impl TextRange) -> Buffers<'_>

An Iterator over the bytes of the Text

Source

pub fn strs(&self, range: impl TextRange) -> Strs<'_>

An Iterator over the &strs of the Text

§Note

The reason why this function returns two strings is that the contents of the text are stored in a GapBuffer, which works with two strings.

If you want to iterate over them, you can do the following:

let text = Text::new();
text.strs(p1..p2).flat_map(str::chars);

Do note that you should avoid iterators like str::lines, as they will separate the line that is partially owned by each &str:

let broken_up_line = [
    "This is line 1, business as usual.\nThis is line 2, but it",
    "is broken into two separate strings.\nSo 4 lines would be counted, instead of 3",
];
§TextRange behavior:

If you give a single usize/Point, it will be interpreted as a range from.

Source

pub fn lines(&self, range: impl TextRange) -> Lines<'_>

Returns an iterator over the lines in a given range

The lines are inclusive, that is, it will iterate over the whole line, not just the parts within the range.

Source

pub fn bytes(&self) -> &Bytes

The inner bytes of the Text

Source

pub fn indent(&self, p: Point, area: &impl RawArea, cfg: PrintCfg) -> usize

Gets the indentation level on the current line

Source

pub fn point_at(&self, b: usize) -> Point

The Point corresponding to the byte position, 0 indexed

If the byte position would fall in between two characters (because the first one comprises more than one byte), the first character is chosen as the Point where the byte is located.

§Panics

Will panic if b is greater than the length of the text

Source

pub fn point_at_char(&self, c: usize) -> Point

The Point associated with a char position, 0 indexed

§Panics

Will panic if c is greater than the number of chars in the text.

Source

pub fn point_at_line(&self, l: usize) -> Point

The Point where the lth line starts, 0 indexed

If l == number_of_lines, returns the last point of the text.

§Panics

Will panic if l is greater than the number of lines on the text

Source

pub fn points_of_line(&self, l: usize) -> [Point; 2]

The start and end Points for a given l line

If l == number_of_lines, these points will be the same.

§Panics

Will panic if the number l is greater than the number of lines on the text

Source

pub fn len_points(&self) -> (Point, Option<Point>)

The points at the end of the text

This will essentially return the last point of the text, alongside the last possible Point of any Ghost at the end of the text.

Source

pub fn last_point(&self) -> Option<Point>

The last Point associated with a char

This will give the Point of the last char of the text. The difference between this method and len is that it will return a Point one position earlier than it. If the text is completely empty, it will return None.

Source

pub fn ghost_max_points_at(&self, at: usize) -> (Point, Option<Point>)

The maximum points in the atth byte

This point is essentially the point at that byte, plus the last possible Point of any Ghosts in that position.

Source

pub fn points_after(&self, tp: impl TwoPoints) -> Option<(Point, Option<Point>)>

Points visually after the TwoPoints

If the TwoPoints in question is concealed, treats the next visible character as the first character, and returns the points of the next visible character.

This method is useful if you want to iterator reversibly right after a certain point, thus including the character of said point.

Source

pub fn visual_line_start(&self, p: impl TwoPoints) -> (Point, Option<Point>)

The visual start of the line

This point is defined not by where the line actually begins, but by where the last ‘\n’ was located. For example, if Tags create ghost text or omit text from multiple different lines, this point may differ from where in the Text the physical line actually begins.

Source

pub fn get_ghost(&self, id: GhostId) -> Option<&Text>

Gets the Ghost of a given GhostId

Source

pub fn to_string(&self) -> String

Clones the inner Bytes as a String

This function will also cut out a final ‘\n’ from the string.

Source

pub fn write_to(&self, writer: impl Write) -> Result<usize>

Writes the contents of this Text to a writer

Source

pub fn has_unsaved_changes(&self) -> bool

Wether or not the content has changed since the last write

Returns true only if the actual bytes of the Text have been changed, ignoring Tags and all the other things, since those are not written to the filesystem.

Source

pub fn iter_fwd(&self, at: impl TwoPoints) -> FwdIter<'_>

A forward iterator of the chars and tags of the Text

Source

pub fn iter_rev(&self, at: impl TwoPoints) -> RevIter<'_>

A reverse iterator of the chars and tags of the Text

Source

pub fn chars_fwd(&self, p: Point) -> impl Iterator<Item = (Point, char)> + '_

A forward iterator of the chars of the Text

Each char will be accompanied by a Point, which is the position where said character starts, e.g. Point::default() for the first character

Source

pub fn chars_rev(&self, p: Point) -> impl Iterator<Item = (Point, char)> + '_

A reverse iterator of the chars of the Text

Each char will be accompanied by a Point, which is the position where said character starts, e.g. Point::default() for the first character

Source

pub fn tags_fwd( &self, b: usize, ) -> Peekable<impl Iterator<Item = (usize, RawTag)> + Clone + 'a>

A forward iterator over the Tags of the Text

This iterator will consider some Tags before b, since their ranges may overlap with b

§Note

Duat works fine with Tags in the middle of a codepoint, but external utilizers may not, so keep that in mind.

Source

pub fn tags_rev( &self, b: usize, ) -> Peekable<impl Iterator<Item = (usize, RawTag)> + Clone + 'a>

An reverse iterator over the Tags of the Text

This iterator will consider some Tags ahead of b, since their ranges may overlap with b

§Note

Duat works fine with Tags in the middle of a codepoint, but external utilizers may not, so keep that in mind.

Source

pub fn raw_tags_fwd(&self, b: usize) -> impl Iterator<Item = (usize, RawTag)>

A forward Iterator over the RawTags

This Iterator does not take into account Tag ranges that intersect with the starting point, unlike Text::tags_fwd

Source

pub fn raw_tags_rev(&self, b: usize) -> impl Iterator<Item = (usize, RawTag)>

A reverse Iterator over the RawTags

This Iterator does not take into account Tag ranges that intersect with the starting point, unlike Text::tags_rev

Source

pub fn selections(&self) -> Option<&Selections>

The Selections printed to this Text, if they exist

Source

pub fn get_contiguous(&self, range: impl TextRange) -> Option<&str>

Assumes that the range given is contiguous in self

You MUST call make_contiguous before using this function. The sole purpose of this function is to not keep the Bytes mutably borrowed.

Trait Implementations§

Source§

impl Clone for Selectionless

Source§

fn clone(&self) -> Selectionless

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 Selectionless

Source§

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

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

impl Deref for Selectionless

Source§

type Target = Text

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl From<Selectionless> for Text

Source§

fn from(value: Selectionless) -> Self

Converts to this type from the input type.
Source§

impl Send for Selectionless

Source§

impl Sync for Selectionless

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.