Struct jumprope::JumpRopeBuf

source ·
pub struct JumpRopeBuf(_);
Expand description

This struct provides an optimized wrapper around JumpRope which buffers adjacent incoming writes before forwarding them to the underlying JumpRope.

Most of the overhead of writing to a rope comes from finding the edit location in the rope and bookkeeping. Because text editing operations are usually sequential, by aggregating adjacent editing operations together we can amortize the cost of updating the underlying data structure itself. This improves performance by about 10x compared to inserting and deleting individual characters.

There is nothing jumprope-specific in this library. It could easily be adapted to wrap other rope libraries (like Ropey) too.

This API is still experimental. This library is only enabled by enabling the “buffered’ feature.

Implementations§

source§

impl JumpRopeBuf

source

pub fn with_rope(rope: JumpRope) -> Self

source

pub fn new() -> Self

source

pub fn new_from_str(s: &str) -> Self

source

pub fn insert(&mut self, pos: usize, content: &str)

Insert new content into the rope at the specified position. This method is semantically equivalent to JumpRope::insert. The only difference is that here we buffer the incoming edit.

source

pub fn remove(&mut self, range: Range<usize>)

Remove content from the rope at the specified position. This method is semantically equivalent to JumpRope::remove. The only difference is that here we buffer the incoming remove operation.

source

pub fn len_chars(&self) -> usize

Return the length of the rope in unicode characters. Note this is not the same as either the number of bytes the characters take, or the number of grapheme clusters in the string.

This method returns the length in constant-time (O(1)).

source

pub fn len_bytes(&self) -> usize

Get the number of bytes used for the UTF8 representation of the rope. This will always match the .len() property of the equivalent String.

source

pub fn is_empty(&self) -> bool

source

pub fn into_inner(self) -> JumpRope

Consume the JumpRopeBuf, flush any buffered operations and return the contained JumpRope.

source

pub fn borrow(&self) -> Ref<'_, JumpRope>

Flush changes into the rope and return a borrowed reference to the rope itself. This makes it easy to call any methods on the underlying rope which aren’t already exposed through the buffered API.

Panics

borrow panics if the value is currently borrowed already.

Trait Implementations§

source§

impl AsMut<JumpRope> for JumpRopeBuf

source§

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

Flush changes into the rope and mutably borrow the rope.

source§

impl Clone for JumpRopeBuf

source§

fn clone(&self) -> Self

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 JumpRopeBuf

source§

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

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

impl Default for JumpRopeBuf

source§

fn default() -> Self

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

impl Display for JumpRopeBuf

source§

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

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

impl From<JumpRope> for JumpRopeBuf

source§

fn from(rope: JumpRope) -> Self

Converts to this type from the input type.
source§

impl<S: AsRef<str>> From<S> for JumpRopeBuf

source§

fn from(str: S) -> Self

Converts to this type from the input type.
source§

impl PartialEq<JumpRope> for JumpRopeBuf

source§

fn eq(&self, other: &JumpRope) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JumpRopeBuf> for JumpRopeBuf

source§

fn eq(&self, other: &JumpRopeBuf) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<String> for &JumpRopeBuf

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: AsRef<str>> PartialEq<T> for JumpRopeBuf

source§

fn eq(&self, other: &T) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<str> for JumpRopeBuf

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for JumpRopeBuf

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V