pub struct Snapshot { /* private fields */ }Expand description
An immutable, Send + Sync copy of the document for background consumers
(e.g. a debounced compile thread).
Creation is O(1) — a rope clone shares structure. The consumer pays for
what it reads: Snapshot::text
is an O(len) materialization that now runs on the consumer’s thread, not
the UI thread; the ranged reads mirror Buffer’s backing-agnostic API.
Implementations§
Source§impl Snapshot
impl Snapshot
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the snapshot is empty (a single empty line — never truly zero).
Sourcepub fn text(&self) -> Cow<'_, str>
pub fn text(&self) -> Cow<'_, str>
The whole snapshot text, LF-only. Borrowed for single-chunk (small)
documents; an O(len) materialization otherwise — run it on the
consumer’s thread.
Sourcepub fn slice(&self, range: Range<u32>) -> Cow<'_, str>
pub fn slice(&self, range: Range<u32>) -> Cow<'_, str>
The text in range (byte offsets on char boundaries). Clamps to the
snapshot end.
Sourcepub fn line(&self, row: u32) -> Cow<'_, str>
pub fn line(&self, row: u32) -> Cow<'_, str>
The text of one row, excluding its trailing \n. Out-of-range rows
return "".
Sourcepub fn line_count(&self) -> u32
pub fn line_count(&self) -> u32
Number of lines. Always ≥ 1; a trailing \n yields a final empty line.