Struct leo_span::source_map::SourceFile

source ·
pub struct SourceFile {
    pub name: FileName,
    pub src: String,
    pub start_pos: BytePos,
    pub end_pos: BytePos,
    lines: Vec<BytePos>,
    multibyte_chars: Vec<MultiByteChar>,
}
Expand description

A single source in the SourceMap.

Fields§

§name: FileName

The name of the file that the source came from.

§src: String

The complete source code.

§start_pos: BytePos

The start position of this source in the SourceMap.

§end_pos: BytePos

The end position of this source in the SourceMap.

§lines: Vec<BytePos>

Locations of line beginnings in the source code.

§multibyte_chars: Vec<MultiByteChar>

Locations of multi-byte characters in the source code.

Implementations§

source§

impl SourceFile

source

fn new(name: FileName, src: String, start_pos: BytePos) -> Self

Creates a new SourceFile given the file name, source contents, and the start_position.

This position is used for analysis purposes.

source

fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos

Converts an absolute BytePos to a CharPos relative to the SourceFile.

source

fn lookup_line(&self, pos: BytePos) -> Option<usize>

Finds the line containing the given position. The return value is the index into the lines array of this SourceFile, not the 1-based line number. If the source file is empty or the position is located before the first line, None is returned.

source

fn lookup_file_pos(&self, pos: BytePos) -> (usize, CharPos)

Looks up the file’s (1-based) line number and (0-based CharPos) column offset, for a given BytePos.

source

fn contents_of_span(&self, span: Span) -> String

Returns contents of a span assumed to be within the given file.

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>,

§

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>,

§

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.