#[non_exhaustive]pub struct Span {
pub start: Marker,
pub end: Marker,
pub indent: Option<usize>,
pub tag_start: Option<Marker>,
}Expand description
A range of locations in a YAML document.
Construct spans with Self::new, Self::empty, or Self::default, then use
Self::with_indent and Self::with_tag_start to attach optional metadata. Fields remain
readable and writable, but the type is non-exhaustive so future releases can add metadata.
Destructuring patterns must include ...
use granit_parser::{Marker, Span};
let start = Marker::new(0, 1, 0);
let end = Marker::new(3, 1, 3);
let span = Span::new(start, end)
.with_indent(Some(0))
.with_tag_start(Some(start));
let Span { start: actual_start, end: actual_end, .. } = span;
assert_eq!(actual_start, start);
assert_eq!(actual_end, end);
assert_eq!(span.indent, Some(0));Direct struct construction outside this crate is not supported:
use granit_parser::{Marker, Span};
let marker = Marker::new(0, 1, 0);
let span = Span { start: marker, end: marker, indent: None, tag_start: None };Struct-update syntax is likewise unavailable; use the builders or assign individual fields:
use granit_parser::{Marker, Span};
let span = Span { indent: Some(2), ..Span::empty(Marker::new(0, 1, 0)) };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: MarkerThe start (inclusive) of the range.
end: MarkerThe end (exclusive) of the range.
indent: Option<usize>Optional indentation hint associated with this span.
This is only meaningful for certain parser-emitted events (notably: block mapping keys).
When indentation is not meaningful or cannot be provided, it must be None.
tag_start: Option<Marker>Optional source marker for the explicit tag token attached to this node.
This is only meaningful for parser-emitted node events that carry a resolved tag, such as
Event::Scalar,
Event::SequenceStart, or
Event::MappingStart. The normal Span::start and
Span::end continue to cover the node value or collection; tag_start points to the
tag token when that token appears at a different source location.
Implementations§
Source§impl Span
impl Span
Sourcepub fn empty(mark: Marker) -> Span
pub fn empty(mark: Marker) -> Span
Create an empty Span at a given location.
An empty span doesn’t contain any characters, but its position may still be meaningful.
For example, for an indented sequence SequenceEnd has a location but an empty span.
Sourcepub fn with_indent(self, indent: Option<usize>) -> Span
pub fn with_indent(self, indent: Option<usize>) -> Span
Return a copy of this Span with the given indentation hint.
Sourcepub fn with_tag_start(self, tag_start: Option<Marker>) -> Span
pub fn with_tag_start(self, tag_start: Option<Marker>) -> Span
Return a copy of this Span with the given explicit tag-token start marker.
Sourcepub fn tag_start(&self) -> Option<Marker>
pub fn tag_start(&self) -> Option<Marker>
Return the source marker of the explicit tag token attached to this node, if any.
The regular span still covers the node value or collection. This accessor is useful for diagnostics that should point at the tag itself, especially when a tagged block collection begins on a later line than the tag token.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the length of the span (in characters).
§Panics
Panics in debug builds if the end marker precedes the start marker.
Sourcepub fn byte_range(&self) -> Option<Range<usize>>
pub fn byte_range(&self) -> Option<Range<usize>>
Return the byte range of the span, if available.