pub struct BufferSnapshot {
pub id: BufferId,
pub cursor: Cursor,
pub file_path: Option<String>,
pub modified: bool,
/* private fields */
}Expand description
Read-only snapshot of buffer state.
A BufferSnapshot captures the complete state of a buffer at a point
in time. Clone is O(1) via Arc structural sharing.
§Cursor Isolation (#471)
Cursor is passed explicitly to from_buffer() - get it from Window.
§Immutability
All methods are read-only. The snapshot cannot be modified after creation, ensuring thread safety without locks.
§Fields Captured
id: Buffer identifiertext: Text content (rope clone, O(1))cursor: Cursor state (passed from Window)file_path: Associated file path (if any)modified: Whether buffer had unsaved changes
Note: Selection removed in Phase 8 (#465) - it now lives in Window. Note: Cursor removed from Buffer in #471 - it now lives in Window.
Fields§
§id: BufferIdBuffer identifier.
cursor: CursorCursor state (from Window, not Buffer).
file_path: Option<String>File path (if buffer is associated with a file).
modified: boolWhether buffer has unsaved modifications.
Implementations§
Source§impl BufferSnapshot
impl BufferSnapshot
Sourcepub fn from_buffer(buffer: &Buffer, cursor: Cursor) -> Self
pub fn from_buffer(buffer: &Buffer, cursor: Cursor) -> Self
Create a snapshot from a buffer.
Cursor must be passed explicitly - get it from Window.
This is O(1) — the rope is cloned via Arc sharing.
Sourcepub fn new(
id: BufferId,
lines: &[String],
cursor: Cursor,
file_path: Option<String>,
modified: bool,
) -> Self
pub fn new( id: BufferId, lines: &[String], cursor: Cursor, file_path: Option<String>, modified: bool, ) -> Self
Create a snapshot from individual components.
This is useful for testing or when constructing a snapshot without a buffer.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Get the number of lines.
Sourcepub fn line(&self, idx: usize) -> Option<&str>
pub fn line(&self, idx: usize) -> Option<&str>
Get a specific line by index.
Returns None if index is out of bounds.
Sourcepub fn lines(&self) -> Vec<String>
pub fn lines(&self) -> Vec<String>
Collect all lines as a Vec<String>.
This allocates — prefer line(idx) for individual access.
Sourcepub fn text_in_range(&self, start: Position, end: Position) -> String
pub fn text_in_range(&self, start: Position, end: Position) -> String
Extract text within a range.
Returns the text between start and end positions.
Positions are clamped to valid bounds.
Sourcepub fn is_valid_position(&self, pos: Position) -> bool
pub fn is_valid_position(&self, pos: Position) -> bool
Check if a position is valid within this snapshot.
Trait Implementations§
Source§impl Clone for BufferSnapshot
impl Clone for BufferSnapshot
Source§fn clone(&self) -> BufferSnapshot
fn clone(&self) -> BufferSnapshot
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more