Skip to main content

BufferSnapshot

Struct BufferSnapshot 

Source
pub struct BufferSnapshot {
    pub id: BufferId,
    pub lines: Vec<String>,
    pub cursor: Cursor,
    pub file_path: Option<String>,
    pub modified: bool,
}
Expand description

Read-only snapshot of buffer state.

A BufferSnapshot captures the complete state of a buffer at a point in time. It’s cheap to clone and safe to share across threads.

§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 identifier
  • lines: All text lines
  • 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: BufferId

Buffer identifier.

§lines: Vec<String>

Text content as lines.

§cursor: Cursor

Cursor state (from Window, not Buffer).

§file_path: Option<String>

File path (if buffer is associated with a file).

§modified: bool

Whether buffer has unsaved modifications.

Implementations§

Source§

impl BufferSnapshot

Source

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 clones all buffer state, so the snapshot is independent of subsequent buffer modifications.

Source

pub const fn new( id: BufferId, lines: Vec<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.

Source

pub const fn line_count(&self) -> usize

Get the number of lines.

Source

pub const fn is_empty(&self) -> bool

Check if the snapshot is empty.

Source

pub fn line(&self, idx: usize) -> Option<&str>

Get a specific line by index.

Returns None if index is out of bounds.

Source

pub fn line_len(&self, idx: usize) -> Option<usize>

Get the length of a line in characters.

Source

pub fn lines(&self) -> &[String]

Get all lines as a slice.

Source

pub fn content(&self) -> String

Get the full content as a string (lines joined with newlines).

Source

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.

Source

pub const fn position(&self) -> Position

Get the cursor position.

Source

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

Source§

fn clone(&self) -> BufferSnapshot

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 BufferSnapshot

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.