pub struct JumpRopeBuf(/* private fields */);
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.