Skip to main content

Span

Struct Span 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§start_line: usize

Line of the start position (1-based).

§start_col: usize

Column of the start position (1-based).

§end_line: usize

Line of the end position (1-based).

§end_col: usize

Column of the end position (1-based).

§start_byte: usize

Byte offset of the node’s first byte in the source (0-based).

§end_byte: usize

Byte offset one past the node’s last byte in the source (0-based, exclusive).

Implementations§

Source§

impl Span

Source

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§

Source§

impl Clone for Span

Source§

fn clone(&self) -> Span

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Span

Source§

impl Debug for Span

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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 Eq for Span

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 (const: unstable) · 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 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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<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<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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, 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.