pub struct SourceMap<'a> { /* private fields */ }Expand description
A line-indexed view of a parsed source.
Byte offsets are zero-based UTF-8 offsets. Lines and columns are one-based, and columns count Unicode scalar values, not bytes. End positions point to the location immediately after the covered byte range.
Implementations§
Source§impl<'a> SourceMap<'a>
impl<'a> SourceMap<'a>
Sourcepub fn new(
source: Option<SourceId>,
name: Option<Cow<'a, str>>,
input: &'a str,
) -> Self
pub fn new( source: Option<SourceId>, name: Option<Cow<'a, str>>, input: &'a str, ) -> Self
Create a source map with a document-local source identifier and optional name.
Sourcepub const fn source_id(&self) -> Option<SourceId>
pub const fn source_id(&self) -> Option<SourceId>
Return this source’s identifier, when it has one.
Sourcepub fn line_column(&self, byte: usize) -> (usize, usize)
pub fn line_column(&self, byte: usize) -> (usize, usize)
Return the line and column for a byte offset.
Offsets past end-of-file are clamped to the end of the source.
Sourcepub fn byte_at_line_column(&self, line: usize, column: usize) -> Option<usize>
pub fn byte_at_line_column(&self, line: usize, column: usize) -> Option<usize>
Return the byte offset for a one-based line and column.
Columns count Unicode scalar values. A column one past the end of the line resolves to the line-end byte offset.
Sourcepub fn span(&self, byte_start: usize, byte_end: usize) -> SourceSpan
pub fn span(&self, byte_start: usize, byte_end: usize) -> SourceSpan
Create a source span for a byte range.
The range is clamped to the source length. The returned span keeps the half-open byte offsets and one-based start/end line-column positions.
Sourcepub fn slice(&self, span: SourceSpan) -> Option<&'a str>
pub fn slice(&self, span: SourceSpan) -> Option<&'a str>
Return a borrowed slice for a source span when it belongs to this source.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for SourceMap<'a>
impl<'a> RefUnwindSafe for SourceMap<'a>
impl<'a> Send for SourceMap<'a>
impl<'a> Sync for SourceMap<'a>
impl<'a> Unpin for SourceMap<'a>
impl<'a> UnsafeUnpin for SourceMap<'a>
impl<'a> UnwindSafe for SourceMap<'a>
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> 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 more