Skip to main content

Snapshot

Struct Snapshot 

Source
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 Window

Implementations§

Source§

impl Snapshot

Source

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. This is O(1) — the rope is cloned via Arc sharing.

Source

pub fn from_parts( lines: &[String], cursor: Position, buffer_id: BufferId, timestamp: SystemTime, ) -> Self

Create a snapshot from components.

This is useful for restoring from serialized data.

Source

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.

Source

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.

Source

pub fn lines(&self) -> Vec<String>

Collect the captured lines as a Vec<String>.

This allocates — prefer line(idx) for individual access.

Source

pub const fn buffer_id(&self) -> BufferId

Get the buffer ID.

Source

pub const fn timestamp(&self) -> SystemTime

Get the timestamp when snapshot was taken.

Source

pub fn matches_buffer(&self, buffer: &Buffer) -> bool

Check if this snapshot matches a buffer’s ID.

Source

pub fn char_count(&self) -> usize

Get the total number of characters in the snapshot.

Source

pub fn line_count(&self) -> usize

Get the number of lines in the snapshot.

Source

pub fn is_empty(&self) -> bool

Check if the snapshot is empty.

Trait Implementations§

Source§

impl Clone for Snapshot

Source§

fn clone(&self) -> Snapshot

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Snapshot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.