pub struct SourceFile {
pub id: SourceId,
pub name: String,
pub contents: Vec<u8>,
/* private fields */
}Expand description
One loaded source file plus its line-start table.
Fields§
§id: SourceIdStable identifier used by spans and diagnostics.
name: StringLogical filename used by diagnostics and include tracking.
contents: Vec<u8>Full source bytes.
Implementations§
Source§impl SourceFile
impl SourceFile
Sourcepub fn new(
id: SourceId,
name: impl Into<String>,
contents: impl Into<Vec<u8>>,
) -> Self
pub fn new( id: SourceId, name: impl Into<String>, contents: impl Into<Vec<u8>>, ) -> Self
Creates a source file and precomputes line starts for span lookup.
Sourcepub fn text(&self) -> Option<&str>
pub fn text(&self) -> Option<&str>
Returns the source contents as UTF-8 when the file is valid UTF-8.
Sourcepub fn span_bytes(&self, span: Span) -> Option<&[u8]>
pub fn span_bytes(&self, span: Span) -> Option<&[u8]>
Returns the raw bytes covered by span when it belongs to this file.
Sourcepub fn span_text(&self, span: Span) -> Option<&str>
pub fn span_text(&self, span: Span) -> Option<&str>
Returns the text covered by span when it belongs to this file.
Sourcepub fn location(&self, offset: usize) -> Option<SourceLocation>
pub fn location(&self, offset: usize) -> Option<SourceLocation>
Resolves a byte offset to a one-based line and column.
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 moreSource§impl Debug for SourceFile
impl Debug for SourceFile
Source§impl<'de> Deserialize<'de> for SourceFile
impl<'de> Deserialize<'de> for SourceFile
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for SourceFile
impl PartialEq for SourceFile
Source§impl Serialize for SourceFile
impl Serialize for SourceFile
impl Eq for SourceFile
impl StructuralPartialEq 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
Compare self to
key and return true if they are equal.