Skip to main content

Span

Struct Span 

Source
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.

Fields§

§start: Marker

The start (inclusive) of the range.

§end: Marker

The 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

Source

pub fn new(start: Marker, end: Marker) -> Span

Create a new Span for the given range.

Source

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.

Source

pub fn with_indent(self, indent: Option<usize>) -> Span

Return a copy of this Span with the given indentation hint.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Return the length of the span (in characters).

Source

pub fn is_empty(&self) -> bool

Return whether the Span has a length of zero.

Source

pub fn byte_range(&self) -> Option<Range<usize>>

Return the byte range of the span, if available.

Source

pub fn slice<'source>(&self, source: &'source str) -> Option<&'source str>

Return the source text covered by this span, if byte offsets are available and the range is valid for the provided input.

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 Default for Span

Source§

fn default() -> Span

Returns the “default value” for a type. 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 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> 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> 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.