pub struct SourceMap { /* private fields */ }
Expand description
Stores all the sources of the current compilation session.
Implementations§
Source§impl SourceMap
impl SourceMap
Sourcepub fn new(hash_kind: SourceFileHashAlgorithm) -> Self
pub fn new(hash_kind: SourceFileHashAlgorithm) -> Self
Creates a new empty source map with the given hash algorithm.
Sourcepub fn set_file_loader(&self, file_loader: impl FileLoader)
pub fn set_file_loader(&self, file_loader: impl FileLoader)
Sets the file loader for the source map.
See its documentation for more details.
Sourcepub fn file_loader(&self) -> &dyn FileLoader
pub fn file_loader(&self) -> &dyn FileLoader
Returns the file loader for the source map.
See its documentation for more details.
Sourcepub fn get_file(&self, path: impl Into<FileName>) -> Option<Arc<SourceFile>>
pub fn get_file(&self, path: impl Into<FileName>) -> Option<Arc<SourceFile>>
Returns the source file with the given path, if it exists. Does not attempt to load the file.
Sourcepub fn load_file(&self, path: &Path) -> Result<Arc<SourceFile>>
pub fn load_file(&self, path: &Path) -> Result<Arc<SourceFile>>
Loads a file from the given path.
Sourcepub fn load_file_with_name(
&self,
name: FileName,
path: &Path,
) -> Result<Arc<SourceFile>>
pub fn load_file_with_name( &self, name: FileName, path: &Path, ) -> Result<Arc<SourceFile>>
Loads a file with the given name from the given path.
Sourcepub fn load_stdin(&self) -> Result<Arc<SourceFile>>
pub fn load_stdin(&self) -> Result<Arc<SourceFile>>
Loads stdin
.
Sourcepub fn new_source_file(
&self,
name: impl Into<FileName>,
src: impl Into<String>,
) -> Result<Arc<SourceFile>>
pub fn new_source_file( &self, name: impl Into<FileName>, src: impl Into<String>, ) -> Result<Arc<SourceFile>>
Creates a new SourceFile
with the given name and source string.
See new_source_file_with
for more details.
Sourcepub fn new_source_file_with(
&self,
filename: FileName,
get_src: impl FnOnce() -> Result<String>,
) -> Result<Arc<SourceFile>>
pub fn new_source_file_with( &self, filename: FileName, get_src: impl FnOnce() -> Result<String>, ) -> Result<Arc<SourceFile>>
Creates a new SourceFile
with the given name and source string closure.
If a file already exists in the SourceMap
with the same ID, that file is returned
unmodified, and get_src
is not called.
Returns an error if the file is larger than 4GiB or other errors occur while creating the
SourceFile
.
Note that the FileLoader
is not used when calling this function.
Sourcepub fn files(&self) -> impl Deref<Target = [Arc<SourceFile>]> + '_
pub fn files(&self) -> impl Deref<Target = [Arc<SourceFile>]> + '_
Returns a read guard to the source files in the source map.
pub fn source_file_by_file_name( &self, filename: &FileName, ) -> Option<Arc<SourceFile>>
pub fn source_file_by_stable_id( &self, stable_id: StableSourceFileId, ) -> Option<Arc<SourceFile>>
pub fn filename_for_diagnostics<'a>( &self, filename: &'a FileName, ) -> FileNameDisplay<'a>
Sourcepub fn is_multiline(&self, span: Span) -> bool
pub fn is_multiline(&self, span: Span) -> bool
Returns true
if the given span is multi-line.
Sourcepub fn span_to_snippet(&self, span: Span) -> Result<String, SpanSnippetError>
pub fn span_to_snippet(&self, span: Span) -> Result<String, SpanSnippetError>
Returns the source snippet as String
corresponding to the given Span
.
Sourcepub fn span_to_prev_source(&self, sp: Span) -> Result<String, SpanSnippetError>
pub fn span_to_prev_source(&self, sp: Span) -> Result<String, SpanSnippetError>
Returns the source snippet as String
before the given Span
.
Sourcepub fn lookup_byte_offset(&self, bpos: BytePos) -> SourceFileAndBytePos
pub fn lookup_byte_offset(&self, bpos: BytePos) -> SourceFileAndBytePos
For a global BytePos
, computes the local offset within the containing SourceFile
.
Sourcepub fn lookup_source_file_idx(&self, pos: BytePos) -> usize
pub fn lookup_source_file_idx(&self, pos: BytePos) -> usize
Returns the index of the SourceFile
(in self.files
) that contains pos
.
This index is guaranteed to be valid for the lifetime of this SourceMap
.
Sourcepub fn lookup_source_file(&self, pos: BytePos) -> Arc<SourceFile>
pub fn lookup_source_file(&self, pos: BytePos) -> Arc<SourceFile>
Return the SourceFile that contains the given BytePos
.
Sourcepub fn lookup_char_pos(&self, pos: BytePos) -> Loc
pub fn lookup_char_pos(&self, pos: BytePos) -> Loc
Looks up source information about a BytePos
.
Sourcepub fn lookup_line(
&self,
pos: BytePos,
) -> Result<SourceFileAndLine, Arc<SourceFile>>
pub fn lookup_line( &self, pos: BytePos, ) -> Result<SourceFileAndLine, Arc<SourceFile>>
If the corresponding SourceFile
is empty, does not return a line number.
pub fn is_valid_span(&self, sp: Span) -> Result<(Loc, Loc), SpanLinesError>
pub fn is_line_before_span_empty(&self, sp: Span) -> bool
pub fn span_to_lines(&self, sp: Span) -> FileLinesResult
Sourcepub fn span_to_source(
&self,
sp: Span,
) -> Result<(Arc<SourceFile>, Range<usize>), SpanSnippetError>
pub fn span_to_source( &self, sp: Span, ) -> Result<(Arc<SourceFile>, Range<usize>), SpanSnippetError>
Returns the source file and the range of text corresponding to the given span.
Sourcepub fn span_to_diagnostic_string(&self, sp: Span) -> impl Display
pub fn span_to_diagnostic_string(&self, sp: Span) -> impl Display
Format the span location to be printed in diagnostics. Must not be emitted to build artifacts as this may leak local file paths. Use span_to_embeddable_string for string suitable for embedding.
pub fn span_to_string(&self, sp: Span) -> impl Display
pub fn span_to_location_info( &self, sp: Span, ) -> (Option<Arc<SourceFile>>, usize, usize, usize, usize)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SourceMap
impl !RefUnwindSafe for SourceMap
impl Send for SourceMap
impl Sync for SourceMap
impl Unpin for SourceMap
impl !UnwindSafe for SourceMap
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, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
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<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: 104 bytes