pub struct Span {
pub file_id: FileId,
pub start: Position,
pub end: Position,
}Expand description
Represents a contiguous range of source code within a single file.
A Span is defined by a start and end Position, marking the beginning
(inclusive) and end (exclusive) of a source code segment.
Fields§
§file_id: FileIdThe unique identifier of the file this span belongs to.
start: PositionThe start position is inclusive, meaning it includes the byte at this position.
end: PositionThe end position is exclusive, meaning it does not include the byte at this position.
Implementations§
Source§impl Span
impl Span
Sourcepub const fn new(file_id: FileId, start: Position, end: Position) -> Self
pub const fn new(file_id: FileId, start: Position, end: Position) -> Self
Creates a new Span from a start and end position.
§Panics
In debug builds, this will panic if the start and end positions are not from the same file (unless one is a dummy position).
Sourcepub const fn zero() -> Self
pub const fn zero() -> Self
Creates a new Span with a zero-length, starting and ending at the same position.
Sourcepub fn dummy(start_offset: u32, end_offset: u32) -> Self
pub fn dummy(start_offset: u32, end_offset: u32) -> Self
Creates a “dummy” span with a null file ID.
Sourcepub fn between(start: Span, end: Span) -> Self
pub fn between(start: Span, end: Span) -> Self
Creates a new span that starts at the beginning of the first span and ends at the conclusion of the second span.
Sourcepub const fn is_zero(&self) -> bool
pub const fn is_zero(&self) -> bool
Checks if this span is a zero-length span, meaning it starts and ends at the same position.
Sourcepub fn join(self, other: Span) -> Span
pub fn join(self, other: Span) -> Span
Creates a new span that encompasses both self and other.
The new span starts at self.start and ends at other.end.
Sourcepub fn to_end(&self, end: Position) -> Span
pub fn to_end(&self, end: Position) -> Span
Creates a new span that starts at the beginning of this span and ends at the specified position.
Sourcepub fn from_start(&self, start: Position) -> Span
pub fn from_start(&self, start: Position) -> Span
Creates a new span that starts at the specified position and ends at the end of this span.
Sourcepub fn subspan(&self, start: u32, end: u32) -> Span
pub fn subspan(&self, start: u32, end: u32) -> Span
Creates a new span that is a subspan of this span, defined by the given byte offsets.
The start and end parameters are relative to the start of this span.
Sourcepub fn contains(&self, position: &impl HasPosition) -> bool
pub fn contains(&self, position: &impl HasPosition) -> bool
Checks if a position is contained within this span’s byte offsets.
Sourcepub fn has_offset(&self, offset: u32) -> bool
pub fn has_offset(&self, offset: u32) -> bool
Checks if a raw byte offset is contained within this span.
Sourcepub fn to_range_usize(&self) -> Range<usize>
pub fn to_range_usize(&self) -> Range<usize>
Converts the span to a Range<usize> of its byte offsets.
Sourcepub fn to_offset_tuple(&self) -> (u32, u32)
pub fn to_offset_tuple(&self) -> (u32, u32)
Converts the span to a tuple of byte offsets.
pub fn is_before(&self, other: &impl HasPosition) -> bool
pub fn is_after(&self, other: &impl HasPosition) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Span
impl<'de> Deserialize<'de> for Span
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>,
Source§impl HasSpan for Span
impl HasSpan for Span
Source§fn start_position(&self) -> Position
fn start_position(&self) -> Position
Source§fn start_offset(&self) -> u32
fn start_offset(&self) -> u32
Source§fn end_position(&self) -> Position
fn end_position(&self) -> Position
Source§fn end_offset(&self) -> u32
fn end_offset(&self) -> u32
Source§impl Ord for Span
impl Ord for Span
Source§impl PartialOrd for Span
impl PartialOrd for Span
Source§impl RangeBounds<u32> for Span
impl RangeBounds<u32> for Span
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 UnwindSafe for Span
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> HasPosition for Twhere
T: HasSpan,
impl<T> HasPosition for Twhere
T: HasSpan,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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