pub struct SourceFile {
pub id: FileId,
pub name: String,
pub src: String,
/* private fields */
}Expand description
Information about a source file.
Fields§
§id: FileIdThe file ID.
name: StringThe file name or path.
src: StringThe source code content.
Implementations§
Source§impl SourceFile
impl SourceFile
Sourcepub fn lookup_line_col(&self, pos: BytePos) -> LineCol
pub fn lookup_line_col(&self, pos: BytePos) -> LineCol
Get the line/column for a byte position.
Sourcepub fn lookup_line(&self, pos: BytePos) -> usize
pub fn lookup_line(&self, pos: BytePos) -> usize
Get the 0-indexed line number for a byte position.
Sourcepub fn source_text(&self, span: Span) -> &str
pub fn source_text(&self, span: Span) -> &str
Get the source text for a span.
Sourcepub fn line_content(&self, line_idx: usize) -> Option<&str>
pub fn line_content(&self, line_idx: usize) -> Option<&str>
Get the content of a specific line (0-indexed).
Sourcepub fn line_start(&self, line_idx: usize) -> Option<BytePos>
pub fn line_start(&self, line_idx: usize) -> Option<BytePos>
Get the byte offset of the start of a line (0-indexed).
Sourcepub fn span_lines(&self, span: Span) -> SpanLines
pub fn span_lines(&self, span: Span) -> SpanLines
Get span information for rendering: start line, start col, end line, end col.
Note: Spans are half-open [lo, hi), so the end position is computed
from the last included byte (hi - 1) for non-empty spans.
Trait Implementations§
Source§impl Clone for SourceFile
impl Clone for SourceFile
Source§fn clone(&self) -> SourceFile
fn clone(&self) -> SourceFile
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SourceFile
impl RefUnwindSafe for SourceFile
impl Send for SourceFile
impl Sync for SourceFile
impl Unpin for SourceFile
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more