pub trait SyntaxCache: Send + Sync {
// Required methods
fn get(&self, byte_range: Range<usize>) -> Option<Vec<Annotation>>;
fn insert(&mut self, byte_range: Range<usize>, highlights: Vec<Annotation>);
fn invalidate_range(&mut self, byte_range: Range<usize>);
fn clear(&mut self);
fn is_empty(&self) -> bool;
}Expand description
Cache for annotation results.
Implementations can provide various caching strategies for annotation data to improve performance.
§Thread Safety
Implementations must be Send + Sync to allow use across threads.
§Example
ⓘ
// Insert annotations for a range
cache.insert(0..100, annotations);
// Later, retrieve cached annotations
if let Some(cached) = cache.get(0..100) {
// Use cached annotations
}
// After an edit, invalidate affected ranges
cache.invalidate_range(50..75);Required Methods§
Sourcefn get(&self, byte_range: Range<usize>) -> Option<Vec<Annotation>>
fn get(&self, byte_range: Range<usize>) -> Option<Vec<Annotation>>
Get cached annotations for a byte range.
Returns None if the range is not cached or cache is stale.
§Arguments
byte_range- The byte range to look up
Sourcefn insert(&mut self, byte_range: Range<usize>, highlights: Vec<Annotation>)
fn insert(&mut self, byte_range: Range<usize>, highlights: Vec<Annotation>)
Insert annotations into the cache.
§Arguments
byte_range- The byte range these annotations coverhighlights- The annotations to cache
Sourcefn invalidate_range(&mut self, byte_range: Range<usize>)
fn invalidate_range(&mut self, byte_range: Range<usize>)
Invalidate cache entries that overlap with a range.
Called after edits to mark affected regions as stale.
§Arguments
byte_range- The byte range that was modified