Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer { /* private fields */ }
Expand description

A single editable text buffer.

Thread ownership: only the caller-selected engine thread mutates a Buffer. All other threads receive RopeSnapshots instead.

Implementations§

Source§

impl Buffer

Source

pub fn empty() -> Self

An empty buffer with a fresh id.

Source

pub fn from_text(text: &str) -> Self

A buffer pre-populated with text.

Source

pub fn synthetic_read_only(text: &str) -> Self

A synthetic, read-only buffer pre-populated with text.

“Synthetic” means the buffer is never persisted: no row in the buffers table, no buffer_edits, no buffer_snapshots, never surfaced in FTS5 or find-in-all. The rope lives only in memory for the lifetime of the process. “Read-only” means the core thread rejects any EditOp or [crate::SelectionEdit] before it reaches the rope.

Used for transient documentation surfaces such as the tutorial tab.

Source

pub fn from_parts(id: BufferId, text: &str, revision: Revision) -> Self

Reconstruct a buffer with a specific id and revision (for persistence recovery). The revision should be the revision the snapshot was taken at; subsequent Self::apply calls advance it normally.

Source

pub fn from_parts_with_file( id: BufferId, text: &str, revision: Revision, file: Option<FileAssociation>, ) -> Self

Reconstruct a buffer with a specific id, revision, and file association.

Source

pub fn is_synthetic(&self) -> bool

true when this buffer is synthetic (never persisted).

Persist clients check this before issuing any write; the core thread skips persist.touch_buffer / persist.upsert_buffer / persist.save_snapshot_async / persist.write_edit for synthetic buffers.

Source

pub fn is_read_only(&self) -> bool

true when this buffer rejects edit application.

The core thread checks this before dispatching to apply_one_edit / apply_selection_edit and returns Error::ReadOnly without touching the rope. Undo / redo operations also no-op on read-only buffers.

Source

pub fn id(&self) -> BufferId

The buffer’s stable id.

Source

pub fn revision(&self) -> Revision

The current revision number.

Source

pub fn rope(&self) -> &Rope

Borrow the rope.

Source

pub fn selections(&self) -> &[Selection]

Borrow the selections.

Source

pub fn set_selections(&mut self, selections: Vec<Selection>)

Replace the selection set.

Source

pub fn undo_tree(&self) -> &UndoTree

Borrow the undo tree.

Source

pub fn undo_tree_mut(&mut self) -> &mut UndoTree

Mutable borrow of the undo tree. Used by the engine owner to insert groups, append records, and step the current pointer along the undo / redo path.

Source

pub fn file_association(&self) -> Option<&FileAssociation>

Borrow the optional filesystem association.

Source

pub fn set_file_association(&mut self, file: Option<FileAssociation>)

Replace the filesystem association.

Source

pub fn capture_removed_text(&self, op: &EditOp) -> Result<String, Error>

Capture the substring op would remove from the current rope, if any. Returns an empty String for EditOp::Insert.

§Errors

Returns Error::Text if the range falls outside the rope.

Source

pub fn snapshot(&self) -> RopeSnapshot

Take a cheap, send-able snapshot of the current rope + revision.

Source

pub fn title(&self, max_chars: usize) -> Option<String>

First non-empty trimmed line of the rope, clipped to max_chars. An empty buffer (or a buffer of pure whitespace) returns None.

Used for buffer-switcher labels and the windows.tabs table when no user-set title exists.

Source

pub fn running_checksum(&self) -> u64

FNV-1a 64-bit hash of the rope’s bytes, maintained incrementally across Self::apply calls. The core thread persists this as buffer_edits.checksum_after; a divergence from a full-walk recomputation is surfaced through event:checksum_drift. See crate::checksum.

Source

pub fn edits_since_verify(&self) -> u32

Number of Self::apply calls since the running checksum was last cross-checked against a full-walk recomputation.

Source

pub fn verify_running_checksum(&mut self) -> (u64, u64)

Re-run a full-walk FNV-1a over the current rope and reseat the running checksum to the freshly-computed value. Returns (observed_before, computed) — observed_before is what the running counter held before reseating; equality means no drift. Also clears Self::edits_since_verify so the next verification is again CHECKSUM_VERIFY_INTERVAL edits away.

Source

pub fn apply(&mut self, op: &EditOp) -> Result<Revision, Error>

Apply an EditOp, advance the revision, and return the new revision.

§Errors

Returns Error::Text if any position in op falls outside the rope. Returns Error::ReadOnly if the buffer is read-only (e.g. a synthetic tutorial buffer); the rope is not touched.

Trait Implementations§

Source§

impl Debug for Buffer

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Buffer

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.