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
impl JumpRopeBuf
pub fn with_rope(rope: JumpRope) -> Self
pub fn new() -> Self
pub fn new_from_str(s: &str) -> Self
sourcepub fn insert(&mut self, pos: usize, content: &str)
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.
sourcepub fn remove(&mut self, range: Range<usize>)
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.
sourcepub fn len_chars(&self) -> usize
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)).
sourcepub fn len_bytes(&self) -> usize
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.
pub fn is_empty(&self) -> bool
sourcepub fn into_inner(self) -> JumpRope
pub fn into_inner(self) -> JumpRope
Consume the JumpRopeBuf, flush any buffered operations and return the contained JumpRope.
sourcepub fn borrow(&self) -> Ref<'_, JumpRope>
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
impl AsMut<JumpRope> for JumpRopeBuf
source§impl Clone for JumpRopeBuf
impl Clone for JumpRopeBuf
source§impl Debug for JumpRopeBuf
impl Debug for JumpRopeBuf
source§impl Default for JumpRopeBuf
impl Default for JumpRopeBuf
source§impl Display for JumpRopeBuf
impl Display for JumpRopeBuf
source§impl From<JumpRope> for JumpRopeBuf
impl From<JumpRope> for JumpRopeBuf
source§impl PartialEq<JumpRope> for JumpRopeBuf
impl PartialEq<JumpRope> for JumpRopeBuf
source§impl PartialEq<JumpRopeBuf> for JumpRopeBuf
impl PartialEq<JumpRopeBuf> for JumpRopeBuf
source§fn eq(&self, other: &JumpRopeBuf) -> bool
fn eq(&self, other: &JumpRopeBuf) -> bool
self
and other
values to be equal, and is used
by ==
.