#[non_exhaustive]pub struct Span {
pub start_line: usize,
pub start_col: usize,
pub end_line: usize,
pub end_col: usize,
pub start_byte: usize,
pub end_byte: usize,
}Expand description
Start and end positions of a node in a code in terms of lines, columns, and byte offsets.
Serialized as a flat object
{start_line, start_col, end_line, end_col, start_byte, end_byte}. The
line/column pairs are 1-based; the byte offsets are 0-based half-open
([start_byte, end_byte)) indices into the parsed source bytes
(Ast::source). The *_line vocabulary aligns the
/ast span field names with the /function and /metrics endpoints
(start_line / end_line), so a client correlating spans across
endpoints no longer special-cases *_row vs *_line per endpoint
(#638). The former start_row / end_row keys were renamed as a
2.0-line break.
The byte offsets let structural consumers slice the original source for a
node — including internal nodes, whose value text the dump omits — so a
caller can recover any subtree’s exact bytes without re-deriving offsets
from lines and columns (#727). They mirror tree-sitter’s own
Node::start_byte / Node::end_byte.
The struct is #[non_exhaustive]: construct it through Span::new and
read its public fields, but do not rely on struct-literal construction or
exhaustive destructuring from outside the crate. This is the last planned
shape break to the type. The two byte fields carry #[serde(default)] so
span objects serialized before they existed still deserialize (the
offsets default to 0).
A node’s span is None for the root and any node when span tracking is
disabled; in that case the wrapping Option<Span> serializes as null.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.start_line: usizeLine of the start position (1-based).
start_col: usizeColumn of the start position (1-based).
end_line: usizeLine of the end position (1-based).
end_col: usizeColumn of the end position (1-based).
start_byte: usizeByte offset of the node’s first byte in the source (0-based).
end_byte: usizeByte offset one past the node’s last byte in the source (0-based, exclusive).
Implementations§
Source§impl Span
impl Span
Sourcepub fn new(
start_line: usize,
start_col: usize,
end_line: usize,
end_col: usize,
start_byte: usize,
end_byte: usize,
) -> Self
pub fn new( start_line: usize, start_col: usize, end_line: usize, end_col: usize, start_byte: usize, end_byte: usize, ) -> Self
Builds a Span from 1-based line/column pairs and 0-based,
half-open byte offsets ([start_byte, end_byte)).
This is the supported construction path now that the struct is
#[non_exhaustive].
Trait Implementations§
impl Copy for Span
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>,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.