pub struct Span {
pub start: usize,
pub end: usize,
}Expand description
A span in source code (byte offsets).
Spans use byte offsets for efficient slicing. Line/column information can be computed from the source text when needed for diagnostics.
Fields§
§start: usizeByte offset of the start of the span (inclusive).
end: usizeByte offset of the end of the span (exclusive).
Implementations§
Source§impl Span
impl Span
Sourcepub fn slice<'a>(&self, source: &'a str) -> &'a str
pub fn slice<'a>(&self, source: &'a str) -> &'a str
Extract the text covered by this span from source.
Sourcepub fn to_positions(&self, source: &str) -> (Position, Position)
pub fn to_positions(&self, source: &str) -> (Position, Position)
Convert byte offset span to line/column positions.
This scans the source text to compute line and column numbers. For performance, avoid calling this repeatedly; cache results if needed.
Trait Implementations§
impl Copy for Span
impl Eq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnsafeUnpin for Span
impl UnwindSafe for Span
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