Skip to main content

Query

Trait Query 

Source
pub trait Query: Send {
    // Required methods
    fn line_count(&self) -> u32;
    fn line(&self, idx: u32) -> &str;
    fn len_bytes(&self) -> usize;
    fn slice(&self, range: Range<Pos>) -> Cow<'_, str>;

    // Provided methods
    fn dirty_gen(&self) -> u64 { ... }
    fn byte_of_row(&self, row: usize) -> usize { ... }
}
Expand description

Read-only query sub-trait of Buffer.

Required Methods§

Source

fn line_count(&self) -> u32

Number of logical lines (excluding the implicit trailing line).

Source

fn line(&self, idx: u32) -> &str

Borrow line idx (0-based). Implementations should panic on out-of-bounds rather than silently return empty.

Source

fn len_bytes(&self) -> usize

Total buffer length in bytes.

Source

fn slice(&self, range: Range<Pos>) -> Cow<'_, str>

Slice for the half-open range. May allocate (rope joins) or borrow (contiguous storage). Returns std::borrow::Cow<'_, str> so contiguous backends can avoid the allocation.

Provided Methods§

Source

fn dirty_gen(&self) -> u64

Monotonic mutation generation counter. Increments on every content-changing call (insert / delete / replace / fold-touch edit / set_content). Read-only ops (cursor moves, queries, view changes) leave it untouched.

Engine consumers cache per-row data (search-match positions, syntax spans, wrap layout) keyed off this counter — when it advances, the cache is invalidated.

Implementations may return any monotonically non-decreasing value (zero is fine for non-canonical impls that don’t have a caching story); the contract is “if dirty_gen changed, the content may have changed.”

Source

fn byte_of_row(&self, row: usize) -> usize

Byte offset of the first byte of row within the buffer’s canonical lines().join("\n") rendering. Out-of-range rows clamp to len_bytes().

Default implementation walks every prior row’s byte length and adds a separator byte per row gap. Backends with a faster path (rope position-of-line) should override.

Pre-0.1.0 default-impl addition — does not extend the sealed surface for downstream impls.

Implementations on Foreign Types§

Source§

impl Query for Buffer

Source§

fn line_count(&self) -> u32

Source§

fn line(&self, idx: u32) -> &str

Source§

fn len_bytes(&self) -> usize

Source§

fn dirty_gen(&self) -> u64

Source§

fn slice(&self, range: Range<Pos>) -> Cow<'_, str>

Implementors§