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: u32Start byte offset (inclusive)
end: u32End byte offset (exclusive)
Implementations§
Source§impl Span
impl Span
Sourcepub const fn from_len(start: u32, len: u32) -> Self
pub const fn from_len(start: u32, len: u32) -> Self
Create a span from start position and length.
Sourcepub const fn contains_span(&self, other: Self) -> bool
pub const fn contains_span(&self, other: Self) -> bool
Check if this span contains another span.
Sourcepub const fn overlaps(&self, other: Self) -> bool
pub const fn overlaps(&self, other: Self) -> bool
Check if this span overlaps with another span.
Sourcepub fn intersect(&self, other: Self) -> Option<Self>
pub fn intersect(&self, other: Self) -> Option<Self>
Get the intersection of two spans, if they overlap.
Sourcepub const fn shrink_start(&self, amount: u32) -> Self
pub const fn shrink_start(&self, amount: u32) -> Self
Shrink this span by removing bytes from the start.
Sourcepub const fn shrink_end(&self, amount: u32) -> Self
pub const fn shrink_end(&self, amount: u32) -> Self
Shrink this span by removing bytes from the end.
Sourcepub const fn first_byte(&self) -> Self
pub const fn first_byte(&self) -> Self
Create a span for just the first byte.
Sourcepub fn slice<'a>(&self, text: &'a str) -> &'a str
pub fn slice<'a>(&self, text: &'a str) -> &'a str
Extract the slice of text covered by this span.
Sourcepub fn slice_safe<'a>(&self, text: &'a str) -> &'a str
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<'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>,
Deserialize this value from the given Serde deserializer. Read more
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.