Skip to main content

spyne_text/buffer/
mod.rs

1pub mod gap_buffer;
2pub mod cursor;
3
4/// A trait for creating and manipulating text buffers.
5/// 
6/// Current implementations: [`GapBuffer`]
7/// Planned implementations: Rope, PieceTable
8pub trait TextBuffer {
9    /// Creates a new text buffer.
10    /// 
11    /// `init_size` parameter determines the initial size of the buffer
12    fn create_buffer(init_size: usize) -> Self where Self: Sized;
13    /// Inserts into a text buffer.
14    /// 
15    /// Inserts `char` at `pos` (0-indexed).
16    /// Reallocates buffer if filled.
17    /// 
18    /// # Panics
19    /// 
20    /// Panics if `pos` is out of bounds.
21    fn insert(&mut self, pos: usize, char: char); 
22    /// Deletes from a text buffer.
23    /// 
24    /// Deletes `len` characters starting at `start` (0-indexed)
25    /// 
26    /// # Panics
27    /// 
28    /// To be filled in later.
29    fn delete(&mut self, start: usize, len: usize);
30    /// Reads from a text buffer.
31    /// 
32    /// Returns a `DoubleEndedIterator` for bidirectional traversal.
33    /// Reads characters from start (0-indexed) to end (exclusive).
34    /// 
35    /// # Panics
36    /// 
37    /// Panics if `start` is out of bounds.
38    /// Panics if `end` is out of bounds.
39    /// Panics if `start` is greater than `end`.
40    fn read(&self, start: usize, end: usize) -> impl DoubleEndedIterator<Item = &char>;
41    /// Returns the current length of a text buffer.
42    fn len(&self) -> usize;
43}