Span

Struct Span 

Source
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: FileId

The unique identifier of the file this span belongs to.

§start: Position

The start position is inclusive, meaning it includes the byte at this position.

§end: Position

The end position is exclusive, meaning it does not include the byte at this position.

Implementations§

Source§

impl Span

Source

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).

Source

pub const fn zero() -> Self

Creates a new Span with a zero-length, starting and ending at the same position.

Source

pub fn dummy(start_offset: u32, end_offset: u32) -> Self

Creates a “dummy” span with a null file ID.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn contains(&self, position: &impl HasPosition) -> bool

Checks if a position is contained within this span’s byte offsets.

Source

pub fn has_offset(&self, offset: u32) -> bool

Checks if a raw byte offset is contained within this span.

Source

pub fn to_range(&self) -> Range<u32>

Converts the span to a Range<u32> of its byte offsets.

Source

pub fn to_range_usize(&self) -> Range<usize>

Converts the span to a Range<usize> of its byte offsets.

Source

pub fn to_offset_tuple(&self) -> (u32, u32)

Converts the span to a tuple of byte offsets.

Source

pub fn length(&self) -> u32

Returns the length of the span in bytes.

Source

pub fn is_before(&self, other: &impl HasPosition) -> bool

Source

pub fn is_after(&self, other: &impl HasPosition) -> bool

Trait Implementations§

Source§

impl Clone for Span

Source§

fn clone(&self) -> Span

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Span

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Span

Source§

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 Display for Span

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&Span> for Range<u32>

Source§

fn from(span: &Span) -> Range<u32>

Converts to this type from the input type.
Source§

impl From<&Span> for Range<usize>

Source§

fn from(span: &Span) -> Range<usize>

Converts to this type from the input type.
Source§

impl From<Span> for Range<u32>

Source§

fn from(span: Span) -> Range<u32>

Converts to this type from the input type.
Source§

impl From<Span> for Range<usize>

Source§

fn from(span: Span) -> Range<usize>

Converts to this type from the input type.
Source§

impl HasFileId for Span

Source§

fn file_id(&self) -> FileId

Returns the unique identifier of the file.
Source§

impl HasSpan for Span

Source§

fn span(&self) -> Span

Returns the source span.
Source§

fn start_position(&self) -> Position

A convenience method to get the starting position of the span.
Source§

fn start_offset(&self) -> u32

A convenience method to get the starting byte offset of the span.
Source§

fn end_position(&self) -> Position

A convenience method to get the ending position of the span.
Source§

fn end_offset(&self) -> u32

A convenience method to get the ending byte offset of the span.
Source§

impl Hash for Span

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Span

Source§

fn cmp(&self, other: &Span) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Span

Source§

fn eq(&self, other: &Span) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Span

Source§

fn partial_cmp(&self, other: &Span) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl RangeBounds<u32> for Span

Source§

fn start_bound(&self) -> Bound<&u32>

Start index bound. Read more
Source§

fn end_bound(&self) -> Bound<&u32>

End index bound. Read more
1.35.0§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
§

fn is_empty(&self) -> bool
where T: PartialOrd,

🔬This is a nightly-only experimental API. (range_bounds_is_empty)
Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more
Source§

impl Serialize for Span

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Span

Source§

impl Eq for Span

Source§

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> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HasPosition for T
where T: HasSpan,

Source§

fn position(&self) -> Position

Returns the source position.
Source§

fn offset(&self) -> u32

A convenience method to get the byte offset of the position.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,