#rope #text-editing #text #text-formatting #user-interface #attributes

flo_rope

An attributed and streaming implementation of the rope data structure

2 unstable releases

0.2.0 Nov 27, 2021
0.1.0 Jun 29, 2020

#748 in Data structures

Download history 53/week @ 2024-07-20 50/week @ 2024-07-27 37/week @ 2024-08-03 61/week @ 2024-08-10 33/week @ 2024-08-17 24/week @ 2024-08-24 36/week @ 2024-08-31 47/week @ 2024-09-07 35/week @ 2024-09-14 72/week @ 2024-09-21 58/week @ 2024-09-28 20/week @ 2024-10-05 34/week @ 2024-10-12 34/week @ 2024-10-19 44/week @ 2024-10-26 50/week @ 2024-11-02

163 downloads per month
Used in flo_binding

Apache-2.0

110KB
2K SLoC

flo_rope

This is a Rust library containing an implementation of the rope data structure. Ropes are an extension of the string type that support efficient manipulation of very large amounts of data.

flo_rope adds a couple of extensions to the usual features of the data structure:

  • It allows for ropes of any 'cell' type so it's not just a replacement for character strings but also vector types with the same editing properties
  • It supports attaching attributes to regions in the rope. This makes it suitable for tasks like representing text with attached formatting information.
  • It supplies a 'push' and 'pull' model for mirroring changes to a rope elsewhere. (for example, to update a user interface in response to changes to the rope)

Ropes are quite typically used for text editors for their performance characteristics: flo_rope provides a way to represent text colours and set up a pipeline to use those colours to perform syntax highlighting. The 'pull' model is highly suited to representing text regions (and other collection data structures) in a reactive user interface.

A companion library, flo_binding will provide support for the reactive model of ropes, suitable for integrating into a user interface.

Examples

Replacing a range in a rope

use flo_rope::*;

let mut rope = AttributedRope::<_, ()>::from(vec![1, 2, 3, 4, 5, 6, 7, 8]);

rope.replace(1..3, vec![42]);
assert!(rope.read_cells(0..rope.len()).cloned().collect::<Vec<_>>() == vec![1,42,4,5,6,7,8]);

No runtime deps