pub struct Span(/* private fields */);
Expand description
A unique identifier for a syntax node.
This is used throughout the compiler to track which source section an error or element stems from. Can be mapped back to a byte range for user facing display.
During editing, the span values stay mostly stable, even for nodes behind an insertion. This is not true for simple ranges as they would shift. Spans can be used as inputs to memoized functions without hurting cache performance when text is inserted somewhere in the document other than the end.
Span ids are ordered in the syntax tree to enable quickly finding the node with some id:
- The id of a parent is always smaller than the ids of any of its children.
- The id of a node is always greater than any id in the subtrees of any left sibling and smaller than any id in the subtrees of any right sibling.
This type takes up 8 bytes and is null-optimized (i.e. Option<Span>
also
takes 8 bytes).
Implementations§
source§impl Span
impl Span
sourcepub const fn is_detached(self) -> bool
pub const fn is_detached(self) -> bool
Whether the span is detached.
sourcepub const fn id(self) -> Option<FileId>
pub const fn id(self) -> Option<FileId>
The id of the source file the span points into.
Returns None
if the span is detached.
sourcepub fn find(iter: impl IntoIterator<Item = Self>) -> Self
pub fn find(iter: impl IntoIterator<Item = Self>) -> Self
Find the first non-detached span in the iterator.
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 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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
key
and return true
if they are equal.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