Struct xswag_base::code::FileMap [] [src]

pub struct FileMap {
    // some fields omitted
}

Stores the content of a file and keeps track of some position meta data, such as linebreaks.

Methods

impl FileMap

fn new<U, V>(filename: U, src: V) -> FileMap where U: Into<String>, V: Into<String>

Creates a new Filemap from existing buffers for the filename and content of the file.

fn filename(&self) -> &str

fn src(&self) -> &str

fn add_line(&self, offset: BytePos)

Adds a new line beginning with the given BytePos to the list. Line beginnings need to be added in order!

fn num_lines(&self) -> usize

Returns the number of lines.

fn get_line_idx(&self, offset: BytePos) -> LineIdx

Returns the (0-based) index of the line in which the byte with the given offset lives.

fn get_loc(&self, offset: BytePos) -> Loc

Returns the location of the given bytes as line and col numbers within this file.

fn get_line(&self, line: LineIdx) -> Option<&str>

Returns the line with the given index or None if it is invalid.

fn get_line_start(&self, line: LineIdx) -> Option<BytePos>

Returns the byte offset of the first symbol in line

fn find_lines(&self)

Searches for line endings and collects all line beginnings in the source string. It starts searching at the latest line beginning in the list so far (or at the beginning of none was added yet).

Normally this is done while lexing to avoid iterating over the whole string multiple times. Mostly handy for tests.

Trait Implementations

impl Debug for FileMap

fn fmt(&self, f: &mut Formatter) -> Result