Skip to main content

Span

Struct Span 

Source
pub struct Span {
    pub start: u32,
    pub end: u32,
}
Expand description

A span of source code, represented as a byte range.

Spans use half-open intervals: [start, end). An empty span has start == end.

Fields§

§start: u32

Start byte offset (inclusive)

§end: u32

End byte offset (exclusive)

Implementations§

Source§

impl Span

Source

pub const fn new(start: u32, end: u32) -> Self

Create a new span from start and end offsets.

Source

pub const fn at(pos: u32) -> Self

Create an empty span at the given position.

Source

pub const fn from_len(start: u32, len: u32) -> Self

Create a span from start position and length.

Source

pub const fn dummy() -> Self

Create a dummy/invalid span (used for synthetic nodes).

Source

pub const fn is_dummy(&self) -> bool

Check if this is a dummy/invalid span.

Source

pub const fn len(&self) -> u32

Get the length of this span in bytes.

Source

pub const fn is_empty(&self) -> bool

Check if this span is empty.

Source

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

Check if this span contains a byte offset.

Source

pub const fn contains_span(&self, other: Self) -> bool

Check if this span contains another span.

Source

pub const fn overlaps(&self, other: Self) -> bool

Check if this span overlaps with another span.

Source

pub const fn merge(&self, other: Self) -> Self

Merge two spans to create a span covering both.

Source

pub fn intersect(&self, other: Self) -> Option<Self>

Get the intersection of two spans, if they overlap.

Source

pub const fn shrink_start(&self, amount: u32) -> Self

Shrink this span by removing bytes from the start.

Source

pub const fn shrink_end(&self, amount: u32) -> Self

Shrink this span by removing bytes from the end.

Source

pub const fn first_byte(&self) -> Self

Create a span for just the first byte.

Source

pub const fn last_byte(&self) -> Self

Create a span for just the last byte.

Source

pub fn slice<'a>(&self, text: &'a str) -> &'a str

Extract the slice of text covered by this span.

Source

pub fn slice_safe<'a>(&self, text: &'a str) -> &'a str

Extract the slice of text covered by this span, with safety checks.

Trait Implementations§

Source§

impl Clone for Span

Source§

fn clone(&self) -> Span

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Source§

fn default() -> Span

Returns the “default value” for a type. 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<(u32, u32)> for Span

Source§

fn from((start, end): (u32, u32)) -> Self

Converts to this type from the input type.
Source§

impl From<Span> for (u32, u32)

Source§

fn from(span: Span) -> Self

Converts to this type from the input type.
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 · Source§

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

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

Source§

fn span(&self) -> Span

Get the source span of this element.
Source§

fn start(&self) -> u32

Get the start byte offset.
Source§

fn end(&self) -> u32

Get the end byte offset.
Source§

fn len(&self) -> u32

Get the length in bytes.
Source§

fn is_empty(&self) -> bool

Check if the span is empty.
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 UnsafeUnpin for Span

§

impl UnwindSafe for Span

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

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