Trait rslint_errors::file::Files[][src]

pub trait Files {
    fn name(&self, id: FileId) -> Option<&str>;
fn source(&self, id: FileId) -> Option<&str>;
fn line_index(&self, file_id: FileId, byte_index: usize) -> Option<usize>;
fn line_range(&self, id: FileId, line_index: usize) -> Option<Range<usize>>; }
Expand description

Interface for interacting with source files that are identified by a unique identifier.

Required methods

Returns the name of the file identified by the id.

Returns the source of the file identified by the id.

The index of the line at the byte index.

Implementation

This can be implemented by caching the results of line_starts and then use binary_search to compute the line index.

match self.line_starts.binary_search(byte_index) {
    Ok(line) => line,
    Err(next_line) => next_line - 1,
}

The byte range of line in the source of the file.

Implementors