lsp_core::prelude

Struct RopeC

Source
pub struct RopeC(pub Rope);
Expand description

Component containing the current source code as ropey::Rope

Tuple Fields§

§0: Rope

Methods from Deref<Target = Rope>§

Source

pub fn write_to<T>(&self, writer: T) -> Result<(), Error>
where T: Write,

Writes the contents of the Rope to a writer.

This is a convenience function, and provides no specific guarantees about performance or internal implementation aside from the runtime complexity listed below.

When more precise control over IO behavior, buffering, etc. is desired, you should handle IO yourself and use the Chunks iterator to iterate through the Rope’s contents.

Runs in O(N) time.

§Errors
  • If the writer returns an error, write_to stops and returns that error.

Note: some data may have been written even if an error is returned.

Source

pub fn len_bytes(&self) -> usize

Total number of bytes in the Rope.

Runs in O(1) time.

Source

pub fn len_chars(&self) -> usize

Total number of chars in the Rope.

Runs in O(1) time.

Source

pub fn len_lines(&self) -> usize

Total number of lines in the Rope.

Runs in O(1) time.

Source

pub fn len_utf16_cu(&self) -> usize

Total number of utf16 code units that would be in Rope if it were encoded as utf16.

Ropey stores text internally as utf8, but sometimes it is necessary to interact with external APIs that still use utf16. This function is primarily intended for such situations, and is otherwise not very useful.

Runs in O(1) time.

Source

pub fn capacity(&self) -> usize

Total size of the Rope’s text buffer space, in bytes.

This includes unoccupied text buffer space. You can calculate the unoccupied space with capacity() - len_bytes(). In general, there will always be some unoccupied buffer space.

Runs in O(N) time.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the Rope’s capacity to the minimum possible.

This will rarely result in capacity() == len_bytes(). Rope stores text in a sequence of fixed-capacity chunks, so an exact fit only happens for texts that are both a precise multiple of that capacity and have code point boundaries that line up exactly with the capacity boundaries.

After calling this, the difference between capacity() and len_bytes() is typically under 1KB per megabyte of text in the Rope.

NOTE: calling this on a Rope clone causes it to stop sharing all data with its other clones. In such cases you will very likely be increasing total memory usage despite shrinking the Rope’s capacity.

Runs in O(N) time, and uses O(log N) additional space during shrinking.

Source

pub fn insert(&mut self, char_idx: usize, text: &str)

Inserts text at char index char_idx.

Runs in O(M + log N) time, where N is the length of the Rope and M is the length of text.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

Source

pub fn insert_char(&mut self, char_idx: usize, ch: char)

Inserts a single char ch at char index char_idx.

Runs in O(log N) time.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

Source

pub fn remove<R>(&mut self, char_range: R)
where R: RangeBounds<usize>,

Removes the text in the given char index range.

Uses range syntax, e.g. 2..7, 2.., etc. The range is in char indices.

Runs in O(M + log N) time, where N is the length of the Rope and M is the length of the range being removed.

§Example
let mut rope = Rope::from_str("Hello world!");
rope.remove(5..);

assert_eq!("Hello", rope);
§Panics

Panics if the start of the range is greater than the end, or if the end is out of bounds (i.e. end > len_chars()).

Source

pub fn split_off(&mut self, char_idx: usize) -> Rope

Splits the Rope at char_idx, returning the right part of the split.

Runs in O(log N) time.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

Source

pub fn append(&mut self, other: Rope)

Appends a Rope to the end of this one, consuming the other Rope.

Runs in O(log N) time.

Source

pub fn byte_to_char(&self, byte_idx: usize) -> usize

Returns the char index of the given byte.

Notes:

  • If the byte is in the middle of a multi-byte char, returns the index of the char that the byte belongs to.
  • byte_idx can be one-past-the-end, which will return one-past-the-end char index.

Runs in O(log N) time.

§Panics

Panics if byte_idx is out of bounds (i.e. byte_idx > len_bytes()).

Source

pub fn byte_to_line(&self, byte_idx: usize) -> usize

Returns the line index of the given byte.

Notes:

  • Lines are zero-indexed. This is functionally equivalent to counting the line endings before the specified byte.
  • byte_idx can be one-past-the-end, which will return the last line index.

Runs in O(log N) time.

§Panics

Panics if byte_idx is out of bounds (i.e. byte_idx > len_bytes()).

Source

pub fn char_to_byte(&self, char_idx: usize) -> usize

Returns the byte index of the given char.

Notes:

  • char_idx can be one-past-the-end, which will return one-past-the-end byte index.

Runs in O(log N) time.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

Source

pub fn char_to_line(&self, char_idx: usize) -> usize

Returns the line index of the given char.

Notes:

  • Lines are zero-indexed. This is functionally equivalent to counting the line endings before the specified char.
  • char_idx can be one-past-the-end, which will return the last line index.

Runs in O(log N) time.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

Source

pub fn char_to_utf16_cu(&self, char_idx: usize) -> usize

Returns the utf16 code unit index of the given char.

Ropey stores text internally as utf8, but sometimes it is necessary to interact with external APIs that still use utf16. This function is primarily intended for such situations, and is otherwise not very useful.

Runs in O(log N) time.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

Source

pub fn utf16_cu_to_char(&self, utf16_cu_idx: usize) -> usize

Returns the char index of the given utf16 code unit.

Ropey stores text internally as utf8, but sometimes it is necessary to interact with external APIs that still use utf16. This function is primarily intended for such situations, and is otherwise not very useful.

Note: if the utf16 code unit is in the middle of a char, returns the index of the char that it belongs to.

Runs in O(log N) time.

§Panics

Panics if utf16_cu_idx is out of bounds (i.e. utf16_cu_idx > len_utf16_cu()).

Source

pub fn line_to_byte(&self, line_idx: usize) -> usize

Returns the byte index of the start of the given line.

Notes:

  • Lines are zero-indexed.
  • line_idx can be one-past-the-end, which will return one-past-the-end byte index.

Runs in O(log N) time.

§Panics

Panics if line_idx is out of bounds (i.e. line_idx > len_lines()).

Source

pub fn line_to_char(&self, line_idx: usize) -> usize

Returns the char index of the start of the given line.

Notes:

  • Lines are zero-indexed.
  • line_idx can be one-past-the-end, which will return one-past-the-end char index.

Runs in O(log N) time.

§Panics

Panics if line_idx is out of bounds (i.e. line_idx > len_lines()).

Source

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

Returns the byte at byte_idx.

Runs in O(log N) time.

§Panics

Panics if byte_idx is out of bounds (i.e. byte_idx >= len_bytes()).

Source

pub fn char(&self, char_idx: usize) -> char

Returns the char at char_idx.

Runs in O(log N) time.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx >= len_chars()).

Source

pub fn line(&self, line_idx: usize) -> RopeSlice<'_>

Returns the line at line_idx.

Note: lines are zero-indexed.

Runs in O(log N) time.

§Panics

Panics if line_idx is out of bounds (i.e. line_idx >= len_lines()).

Source

pub fn chunk_at_byte(&self, byte_idx: usize) -> (&str, usize, usize, usize)

Returns the chunk containing the given byte index.

Also returns the byte and char indices of the beginning of the chunk and the index of the line that the chunk starts on.

Note: for convenience, a one-past-the-end byte_idx returns the last chunk of the RopeSlice.

The return value is organized as (chunk, chunk_byte_idx, chunk_char_idx, chunk_line_idx).

Runs in O(log N) time.

§Panics

Panics if byte_idx is out of bounds (i.e. byte_idx > len_bytes()).

Source

pub fn chunk_at_char(&self, char_idx: usize) -> (&str, usize, usize, usize)

Returns the chunk containing the given char index.

Also returns the byte and char indices of the beginning of the chunk and the index of the line that the chunk starts on.

Note: for convenience, a one-past-the-end char_idx returns the last chunk of the RopeSlice.

The return value is organized as (chunk, chunk_byte_idx, chunk_char_idx, chunk_line_idx).

Runs in O(log N) time.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

Source

pub fn chunk_at_line_break( &self, line_break_idx: usize, ) -> (&str, usize, usize, usize)

Returns the chunk containing the given line break.

Also returns the byte and char indices of the beginning of the chunk and the index of the line that the chunk starts on.

Note: for convenience, both the beginning and end of the rope are considered line breaks for the purposes of indexing. For example, in the string "Hello \n world!" 0 would give the first chunk, 1 would give the chunk containing the newline character, and 2 would give the last chunk.

The return value is organized as (chunk, chunk_byte_idx, chunk_char_idx, chunk_line_idx).

Runs in O(log N) time.

§Panics

Panics if line_break_idx is out of bounds (i.e. line_break_idx > len_lines()).

Source

pub fn slice<R>(&self, char_range: R) -> RopeSlice<'_>
where R: RangeBounds<usize>,

Gets an immutable slice of the Rope, using char indices.

Uses range syntax, e.g. 2..7, 2.., etc.

§Example
let rope = Rope::from_str("Hello world!");
let slice = rope.slice(..5);

assert_eq!("Hello", slice);

Runs in O(log N) time.

§Panics

Panics if the start of the range is greater than the end, or if the end is out of bounds (i.e. end > len_chars()).

Source

pub fn byte_slice<R>(&self, byte_range: R) -> RopeSlice<'_>
where R: RangeBounds<usize>,

Gets and immutable slice of the Rope, using byte indices.

Uses range syntax, e.g. 2..7, 2.., etc.

Runs in O(log N) time.

§Panics

Panics if:

  • The start of the range is greater than the end.
  • The end is out of bounds (i.e. end > len_bytes()).
  • The range doesn’t align with char boundaries.
Source

pub fn bytes(&self) -> Bytes<'_>

Creates an iterator over the bytes of the Rope.

Runs in O(log N) time.

Source

pub fn bytes_at(&self, byte_idx: usize) -> Bytes<'_>

Creates an iterator over the bytes of the Rope, starting at byte byte_idx.

If byte_idx == len_bytes() then an iterator at the end of the Rope is created (i.e. next() will return None).

Runs in O(log N) time.

§Panics

Panics if byte_idx is out of bounds (i.e. byte_idx > len_bytes()).

Source

pub fn chars(&self) -> Chars<'_>

Creates an iterator over the chars of the Rope.

Runs in O(log N) time.

Source

pub fn chars_at(&self, char_idx: usize) -> Chars<'_>

Creates an iterator over the chars of the Rope, starting at char char_idx.

If char_idx == len_chars() then an iterator at the end of the Rope is created (i.e. next() will return None).

Runs in O(log N) time.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

Source

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

Creates an iterator over the lines of the Rope.

Runs in O(log N) time.

Source

pub fn lines_at(&self, line_idx: usize) -> Lines<'_>

Creates an iterator over the lines of the Rope, starting at line line_idx.

If line_idx == len_lines() then an iterator at the end of the Rope is created (i.e. next() will return None).

Runs in O(log N) time.

§Panics

Panics if line_idx is out of bounds (i.e. line_idx > len_lines()).

Source

pub fn chunks(&self) -> Chunks<'_>

Creates an iterator over the chunks of the Rope.

Runs in O(log N) time.

Source

pub fn chunks_at_byte( &self, byte_idx: usize, ) -> (Chunks<'_>, usize, usize, usize)

Creates an iterator over the chunks of the Rope, with the iterator starting at the chunk containing byte_idx.

Also returns the byte and char indices of the beginning of the first chunk to be yielded, and the index of the line that chunk starts on.

If byte_idx == len_bytes() an iterator at the end of the Rope (yielding None on a call to next()) is created.

The return value is organized as (iterator, chunk_byte_idx, chunk_char_idx, chunk_line_idx).

Runs in O(log N) time.

§Panics

Panics if byte_idx is out of bounds (i.e. byte_idx > len_bytes()).

Source

pub fn chunks_at_char( &self, char_idx: usize, ) -> (Chunks<'_>, usize, usize, usize)

Creates an iterator over the chunks of the Rope, with the iterator starting at the chunk containing char_idx.

Also returns the byte and char indices of the beginning of the first chunk to be yielded, and the index of the line that chunk starts on.

If char_idx == len_chars() an iterator at the end of the Rope (yielding None on a call to next()) is created.

The return value is organized as (iterator, chunk_byte_idx, chunk_char_idx, chunk_line_idx).

Runs in O(log N) time.

§Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

Source

pub fn chunks_at_line_break( &self, line_break_idx: usize, ) -> (Chunks<'_>, usize, usize, usize)

Creates an iterator over the chunks of the Rope, with the iterator starting at the chunk containing line_break_idx.

Also returns the byte and char indices of the beginning of the first chunk to be yielded, and the index of the line that chunk starts on.

Note: for convenience, both the beginning and end of the Rope are considered line breaks for the purposes of indexing. For example, in the string "Hello \n world!" 0 would create an iterator starting on the first chunk, 1 would create an iterator starting on the chunk containing the newline character, and 2 would create an iterator at the end of the Rope (yielding None on a call to next()).

The return value is organized as (iterator, chunk_byte_idx, chunk_char_idx, chunk_line_idx).

Runs in O(log N) time.

§Panics

Panics if line_break_idx is out of bounds (i.e. line_break_idx > len_lines()).

Source

pub fn is_instance(&self, other: &Rope) -> bool

Returns true if this rope and other point to precisely the same in-memory data.

This happens when one of the ropes is a clone of the other and neither have been modified since then. Because clones initially share all the same data, it can be useful to check if they still point to precisely the same memory as a way of determining whether they are both still unmodified.

Note: this is distinct from checking for equality: two ropes can have the same contents (equal) but be stored in different memory locations (not instances). Importantly, two clones that post-cloning are modified identically will not be instances anymore, even though they will have equal contents.

Runs in O(1) time.

Source

pub fn try_insert(&mut self, char_idx: usize, text: &str) -> Result<(), Error>

Non-panicking version of insert().

Source

pub fn try_insert_char( &mut self, char_idx: usize, ch: char, ) -> Result<(), Error>

Non-panicking version of insert_char().

Source

pub fn try_remove<R>(&mut self, char_range: R) -> Result<(), Error>
where R: RangeBounds<usize>,

Non-panicking version of remove().

Source

pub fn try_split_off(&mut self, char_idx: usize) -> Result<Rope, Error>

Non-panicking version of split_off().

Source

pub fn try_byte_to_char(&self, byte_idx: usize) -> Result<usize, Error>

Non-panicking version of byte_to_char().

Source

pub fn try_byte_to_line(&self, byte_idx: usize) -> Result<usize, Error>

Non-panicking version of byte_to_line().

Source

pub fn try_char_to_byte(&self, char_idx: usize) -> Result<usize, Error>

Non-panicking version of char_to_byte().

Source

pub fn try_char_to_line(&self, char_idx: usize) -> Result<usize, Error>

Non-panicking version of char_to_line().

Source

pub fn try_char_to_utf16_cu(&self, char_idx: usize) -> Result<usize, Error>

Non-panicking version of char_to_utf16_cu().

Source

pub fn try_utf16_cu_to_char(&self, utf16_cu_idx: usize) -> Result<usize, Error>

Non-panicking version of utf16_cu_to_char().

Source

pub fn try_line_to_byte(&self, line_idx: usize) -> Result<usize, Error>

Non-panicking version of line_to_byte().

Source

pub fn try_line_to_char(&self, line_idx: usize) -> Result<usize, Error>

Non-panicking version of line_to_char().

Source

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

Non-panicking version of byte().

Source

pub fn get_char(&self, char_idx: usize) -> Option<char>

Non-panicking version of char().

Source

pub fn get_line(&self, line_idx: usize) -> Option<RopeSlice<'_>>

Non-panicking version of line().

Source

pub fn get_chunk_at_byte( &self, byte_idx: usize, ) -> Option<(&str, usize, usize, usize)>

Non-panicking version of chunk_at_byte().

Source

pub fn get_chunk_at_char( &self, char_idx: usize, ) -> Option<(&str, usize, usize, usize)>

Non-panicking version of chunk_at_char().

Source

pub fn get_chunk_at_line_break( &self, line_break_idx: usize, ) -> Option<(&str, usize, usize, usize)>

Non-panicking version of chunk_at_line_break().

Source

pub fn get_slice<R>(&self, char_range: R) -> Option<RopeSlice<'_>>
where R: RangeBounds<usize>,

Non-panicking version of slice().

Source

pub fn get_byte_slice<R>(&self, byte_range: R) -> Option<RopeSlice<'_>>
where R: RangeBounds<usize>,

Non-panicking version of byte_slice().

Source

pub fn get_bytes_at(&self, byte_idx: usize) -> Option<Bytes<'_>>

Non-panicking version of bytes_at().

Source

pub fn get_chars_at(&self, char_idx: usize) -> Option<Chars<'_>>

Non-panicking version of chars_at().

Source

pub fn get_lines_at(&self, line_idx: usize) -> Option<Lines<'_>>

Non-panicking version of lines_at().

Source

pub fn get_chunks_at_byte( &self, byte_idx: usize, ) -> Option<(Chunks<'_>, usize, usize, usize)>

Non-panicking version of chunks_at_byte().

Source

pub fn get_chunks_at_char( &self, char_idx: usize, ) -> Option<(Chunks<'_>, usize, usize, usize)>

Non-panicking version of chunks_at_char().

Source

pub fn get_chunks_at_line_break( &self, line_break_idx: usize, ) -> Option<(Chunks<'_>, usize, usize, usize)>

Non-panicking version of chunks_at_line_break().

Trait Implementations§

Source§

impl AsMut<Rope> for RopeC

Source§

fn as_mut(&mut self) -> &mut Rope

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Rope> for RopeC

Source§

fn as_ref(&self) -> &Rope

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Component for RopeC
where Self: Send + Sync + 'static,

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Source§

fn register_component_hooks(_hooks: &mut ComponentHooks)

Called when registering this component, allowing mutable access to its ComponentHooks.
Source§

impl Debug for RopeC

Source§

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

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

impl DerefMut for RopeC

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Deref for RopeC

Source§

type Target = Rope

The resulting type after dereferencing.
Source§

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

Dereferences the value.

Auto Trait Implementations§

§

impl Freeze for RopeC

§

impl RefUnwindSafe for RopeC

§

impl Send for RopeC

§

impl Sync for RopeC

§

impl Unpin for RopeC

§

impl UnwindSafe for RopeC

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<C> Bundle for C
where C: Component,

Source§

fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )

Source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

Source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

Gets this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl<T> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<C> DynamicBundle for C
where C: Component,

Source§

fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T