#[non_exhaustive]pub struct SourceFile {
pub name: FileName,
pub src: Arc<String>,
pub start_pos: BytePos,
pub source_len: RelativeBytePos,
pub lines: Vec<RelativeBytePos>,
pub multibyte_chars: Vec<MultiByteChar>,
}
Expand description
A single source in the SourceMap
.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.name: FileName
The name of the file that the source came from. Source that doesn’t
originate from files has names between angle brackets by convention
(e.g., <stdin>
).
src: Arc<String>
The complete source code.
start_pos: BytePos
The start position of this source in the SourceMap
.
source_len: RelativeBytePos
The byte length of this source.
lines: Vec<RelativeBytePos>
Locations of lines beginnings in the source code.
multibyte_chars: Vec<MultiByteChar>
Locations of multi-byte characters in the source code.
Implementations§
Source§impl SourceFile
impl SourceFile
pub fn lines(&self) -> &[RelativeBytePos]
pub fn count_lines(&self) -> usize
pub fn absolute_position(&self, pos: RelativeBytePos) -> BytePos
pub fn relative_position(&self, pos: BytePos) -> RelativeBytePos
pub fn end_position(&self) -> BytePos
Sourcepub fn lookup_line(&self, pos: RelativeBytePos) -> Option<usize>
pub fn lookup_line(&self, pos: RelativeBytePos) -> 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.
Sourcepub fn line_position(&self, line_number: usize) -> Option<usize>
pub fn line_position(&self, line_number: usize) -> Option<usize>
Returns the relative byte position of the start of the line at the given 0-based line index.
Sourcepub fn lookup_file_pos_with_col_display(
&self,
pos: BytePos,
) -> (usize, CharPos, usize)
pub fn lookup_file_pos_with_col_display( &self, pos: BytePos, ) -> (usize, CharPos, usize)
Looks up the file’s (1-based) line number, (0-based CharPos
) column offset, and (0-based)
column offset when displayed, for a given BytePos
.
Sourcepub fn get_line(&self, line_number: usize) -> Option<&str>
pub fn get_line(&self, line_number: usize) -> Option<&str>
Gets a line from the list of pre-computed line-beginnings. The line number here is 0-based.
Sourcepub fn get_lines(&self, range: RangeInclusive<usize>) -> Option<&str>
pub fn get_lines(&self, range: RangeInclusive<usize>) -> Option<&str>
Gets a slice of the source text between two lines, including the terminator of the second line (if any).
Sourcepub fn contains(&self, byte_pos: BytePos) -> bool
pub fn contains(&self, byte_pos: BytePos) -> bool
Returns whether or not the file contains the given SourceMap
byte
position. The position one past the end of the file is considered to be
contained by the file. This implies that files for which is_empty
returns true still contain one byte position according to this function.
pub fn is_empty(&self) -> bool
Sourcepub fn original_relative_byte_pos(&self, pos: BytePos) -> RelativeBytePos
pub fn original_relative_byte_pos(&self, pos: BytePos) -> RelativeBytePos
Calculates the original byte position relative to the start of the file based on the given byte position.
Trait Implementations§
Source§impl Clone for SourceFile
impl Clone for SourceFile
Source§fn clone(&self) -> SourceFile
fn clone(&self) -> SourceFile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SourceFile
impl Debug for SourceFile
Source§impl Hash for SourceFile
impl Hash for SourceFile
Source§impl PartialEq for SourceFile
impl PartialEq for SourceFile
impl Eq for SourceFile
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
fn equivalent(&self, key: &K) -> bool
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<Q> ToOwnedEquivalent<<Q as ToOwned>::Owned> for Q
impl<Q> ToOwnedEquivalent<<Q as ToOwned>::Owned> for Q
fn to_owned_equivalent(&self) -> <Q as ToOwned>::Owned
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 96 bytes