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
impl SourceFile
Sourcefn new(name: FileName, src: String, start_pos: BytePos) -> Self
fn new(name: FileName, src: String, start_pos: BytePos) -> Self
Creates a new SourceFile
given the file name
,
source contents, and the start_pos
ition.
This position is used for analysis purposes.
Sourcefn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos
fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos
Converts an absolute BytePos
to a CharPos
relative to the SourceFile
.
Sourcefn lookup_line(&self, pos: BytePos) -> Option<usize>
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.
Sourcefn lookup_file_pos(&self, pos: BytePos) -> (usize, CharPos)
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
.
Sourcefn contents_of_span(&self, span: Span) -> String
fn contents_of_span(&self, span: Span) -> String
Returns contents of a span
assumed to be within the given file.
Auto Trait Implementations§
impl Freeze for SourceFile
impl RefUnwindSafe for SourceFile
impl Send for SourceFile
impl Sync for SourceFile
impl Unpin for SourceFile
impl UnwindSafe for SourceFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more