pub struct Snapshot { /* private fields */ }Expand description
A captured buffer state.
Snapshots are used for:
- Safety checkpoints before complex operations
- Crash recovery
- Cursor restoration when reopening files
§Cursor Isolation (#471)
Cursor is passed explicitly to capture() and returned from restore().
The caller manages cursor via Window, not Buffer.
§File Storage
This struct provides accessors for all data needed by the driver layer to serialize/deserialize to files. The kernel does not handle serialization directly.
§Example
use reovim_kernel::api::v1::*;
// Create a buffer with some content
let mut buffer = Buffer::from_string("Hello, World!");
let cursor = Position::new(0, 0); // Get from Window in real usage
// Capture state with explicit cursor
let snapshot = Snapshot::capture(&buffer, cursor);
// Later, restore the state
let restored_cursor = snapshot.restore(&mut buffer);
// Caller sets restored_cursor to WindowImplementations§
Source§impl Snapshot
impl Snapshot
Sourcepub fn capture(buffer: &Buffer, cursor: Position) -> Self
pub fn capture(buffer: &Buffer, cursor: Position) -> Self
Capture the current state of a buffer.
Cursor position must be passed explicitly - get it from Window.
Sourcepub const fn from_parts(
lines: Vec<String>,
cursor: Position,
buffer_id: BufferId,
timestamp: SystemTime,
) -> Self
pub const fn from_parts( lines: Vec<String>, cursor: Position, buffer_id: BufferId, timestamp: SystemTime, ) -> Self
Create a snapshot from components.
This is useful for restoring from serialized data.
Sourcepub fn restore(&self, buffer: &mut Buffer) -> Position
pub fn restore(&self, buffer: &mut Buffer) -> Position
Restore a buffer to this snapshot’s state.
Returns the cursor position that should be set on Window. The buffer ID is not changed.
Sourcepub const fn cursor(&self) -> Position
pub const fn cursor(&self) -> Position
Get the cursor position from this snapshot.
Use this when reopening a file that already has its content loaded - just get the cursor position to set on Window.
Sourcepub const fn timestamp(&self) -> SystemTime
pub const fn timestamp(&self) -> SystemTime
Get the timestamp when snapshot was taken.
Sourcepub fn matches_buffer(&self, buffer: &Buffer) -> bool
pub fn matches_buffer(&self, buffer: &Buffer) -> bool
Check if this snapshot matches a buffer’s ID.
Sourcepub fn char_count(&self) -> usize
pub fn char_count(&self) -> usize
Get the total number of characters in the snapshot.
Sourcepub const fn line_count(&self) -> usize
pub const fn line_count(&self) -> usize
Get the number of lines in the snapshot.