pub struct Spanned<T> {
pub span: Span,
pub value: T,
pub comments: Vec<Spanned<Comment>>,
}Expand description
A syntax node with source span information attached.
This is the universal wrapper for AST nodes, analogous to:
A.Locatedin elm/compilerNodein stil4m/elm-syntaxSpannedin many Rust parser crates
Each node carries optional leading comments — comments that appeared immediately before this node in source. This enables round-tripping of comments inside expressions (let-in, case-of, etc.).
Fields§
§span: Span§value: T§comments: Vec<Spanned<Comment>>Leading comments that appeared immediately before this node in source.
Implementations§
Source§impl<T> Spanned<T>
impl<T> Spanned<T>
Sourcepub fn dummy(value: T) -> Self
pub fn dummy(value: T) -> Self
Create a spanned node with a dummy span (for synthesized/constructed nodes).
Sourcepub fn map<U>(self, f: impl FnOnce(T) -> U) -> Spanned<U>
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Spanned<U>
Map the inner value, preserving the span and comments.
Sourcepub fn with_comments(self, comments: Vec<Spanned<Comment>>) -> Self
pub fn with_comments(self, comments: Vec<Spanned<Comment>>) -> Self
Attach leading comments to this node.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwrap the spanned node, discarding the span.
Trait Implementations§
Source§impl<T: PartialEq> PartialEq for Spanned<T>
impl<T: PartialEq> PartialEq for Spanned<T>
impl<T: Eq> Eq for Spanned<T>
impl<T> StructuralPartialEq for Spanned<T>
Auto Trait Implementations§
impl<T> Freeze for Spanned<T>where
T: Freeze,
impl<T> RefUnwindSafe for Spanned<T>where
T: RefUnwindSafe,
impl<T> Send for Spanned<T>where
T: Send,
impl<T> Sync for Spanned<T>where
T: Sync,
impl<T> Unpin for Spanned<T>where
T: Unpin,
impl<T> UnsafeUnpin for Spanned<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Spanned<T>where
T: UnwindSafe,
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