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§
Sourcefn line_count(&self) -> u32
fn line_count(&self) -> u32
Number of logical lines (excluding the implicit trailing line).
Provided Methods§
Sourcefn dirty_gen(&self) -> u64
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.”
Sourcefn byte_of_row(&self, row: usize) -> usize
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.