pub struct SourceFile {
pub name: String,
pub text: String,
/* private fields */
}Expand description
One source file with a line index.
Fields§
§name: StringName shown in diagnostics.
text: StringFile contents.
Implementations§
Source§impl SourceFile
impl SourceFile
Sourcepub fn new(name: impl Into<String>, text: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, text: impl Into<String>) -> Self
Creates a source file and indexes its lines.
Sourcepub fn line_col(&self, offset: usize) -> (usize, usize)
pub fn line_col(&self, offset: usize) -> (usize, usize)
1-based line and column (in characters) of a byte offset.
Sourcepub fn line_text(&self, line: usize) -> &str
pub fn line_text(&self, line: usize) -> &str
Text of a 1-based line without its line terminator.
Sourcepub fn line_start(&self, line: usize) -> usize
pub fn line_start(&self, line: usize) -> usize
Byte offset where a 1-based line starts.
Trait Implementations§
Source§impl Clone for SourceFile
impl Clone 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 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