FileMap

Struct FileMap 

Source
pub struct FileMap { /* private fields */ }
Expand description

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

Implementations§

Source§

impl FileMap

Source

pub 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.

Source

pub fn filename(&self) -> &str

Source

pub fn src(&self) -> &str

Source

pub 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!

Source

pub fn num_lines(&self) -> usize

Returns the number of lines.

Source

pub 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.

Source

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

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

Source

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

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

Source

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

Returns the byte offset of the first symbol in line

Source

pub 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§

Source§

impl Debug for FileMap

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.