Skip to main content

Event

Enum Event 

Source
pub enum Event<'input> {
    StreamStart,
    StreamEnd,
    Comment {
        text: &'input str,
    },
    Alias {
        name: &'input str,
    },
    DocumentStart {
        explicit: bool,
        version: Option<(u8, u8)>,
        tag_directives: Vec<(String, String)>,
    },
    DocumentEnd {
        explicit: bool,
    },
    SequenceStart {
        anchor: Option<&'input str>,
        tag: Option<Cow<'input, str>>,
        style: CollectionStyle,
    },
    SequenceEnd,
    MappingStart {
        anchor: Option<&'input str>,
        tag: Option<Cow<'input, str>>,
        style: CollectionStyle,
    },
    MappingEnd,
    Scalar {
        value: Cow<'input, str>,
        style: ScalarStyle,
        anchor: Option<&'input str>,
        tag: Option<Cow<'input, str>>,
    },
}
Expand description

A high-level YAML parse event.

Variants§

§

StreamStart

The YAML stream has started.

Always the first event in any parse. The associated span is a zero-width span at crate::pos::Pos::ORIGIN.

§

StreamEnd

The YAML stream has ended.

Always the last event in any parse. The associated span is a zero-width span at the position immediately after the last byte of input.

§

Comment

A YAML comment (YAML 1.2 §6.6).

text is the comment body — the content of the line after the # character, with the # itself excluded. Leading whitespace after # is preserved (e.g. # hello → text " hello"; #nospace → text "nospace"). The associated span covers from the # character through the last byte of comment text (the newline is not included).

One Comment event is emitted per physical line.

Fields

§text: &'input str

Comment body (everything after the #, excluding the newline).

§

Alias

An alias node (*name) that references a previously anchored node.

The associated span covers the entire *name token (from * through the last character of the name). Resolution of the alias to its anchored node is the loader’s responsibility (Task 20) — the parser emits this event without expansion.

Fields

§name: &'input str

The anchor name being referenced (e.g. "foo" for *foo). Borrowed directly from input — no allocation.

§

DocumentStart

A document has started.

explicit is true when the document was introduced with ---. false for bare documents (no marker).

Fields

§explicit: bool

Whether the document was introduced with ---.

§version: Option<(u8, u8)>

Version from the %YAML directive preceding this document, if any.

Some((1, 2)) for %YAML 1.2, None when no %YAML directive was present.

§tag_directives: Vec<(String, String)>

Tag handle/prefix pairs from %TAG directives preceding this document.

Each entry is (handle, prefix) — e.g. ("!foo!", "tag:example.com,2026:"). Empty when no %TAG directives were present.

§

DocumentEnd

A document has ended.

explicit is true when the document was closed with .... false for implicitly-ended documents.

Fields

§explicit: bool

Whether the document was closed with ....

§

SequenceStart

A block or flow sequence has started.

Followed by zero or more node events (scalars or nested collections), then a matching Event::SequenceEnd.

Fields

§anchor: Option<&'input str>

The anchor name, if any (e.g. &foo).

§tag: Option<Cow<'input, str>>

The resolved tag, if any (e.g. "tag:yaml.org,2002:seq" for !!seq).

Verbatim tags (!<URI>) borrow from input. Shorthand tags resolved via %TAG directives or the built-in !! default produce owned strings.

§style: CollectionStyle

Whether this is a block (- indicator) or flow ([...]) sequence.

§

SequenceEnd

A sequence has ended.

Matches the most recent Event::SequenceStart on the event stack.

§

MappingStart

A block or flow mapping has started.

Followed by alternating key/value node events (scalars or nested collections), then a matching Event::MappingEnd.

Fields

§anchor: Option<&'input str>

The anchor name, if any (e.g. &foo).

§tag: Option<Cow<'input, str>>

The resolved tag, if any (e.g. "tag:yaml.org,2002:map" for !!map).

See [SequenceStart::tag] for resolution semantics.

§style: CollectionStyle

Whether this is a block (indentation-based) or flow ({...}) mapping.

§

MappingEnd

A mapping has ended.

Matches the most recent Event::MappingStart on the event stack.

§

Scalar

A scalar value.

value borrows from input when no transformation is required (the vast majority of plain scalars). It owns when line folding produces a string that doesn’t exist contiguously in the input.

Fields

§value: Cow<'input, str>

The scalar’s decoded value.

§style: ScalarStyle

The style in which the scalar appeared in the source.

§anchor: Option<&'input str>

The anchor name, if any (e.g. &foo).

§tag: Option<Cow<'input, str>>

The resolved tag, if any (e.g. "tag:yaml.org,2002:str" for !!str).

See [SequenceStart::tag] for resolution semantics.

Trait Implementations§

Source§

impl<'input> Clone for Event<'input>

Source§

fn clone(&self) -> Event<'input>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'input> Debug for Event<'input>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'input> PartialEq for Event<'input>

Source§

fn eq(&self, other: &Event<'input>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<'input> Eq for Event<'input>

Source§

impl<'input> StructuralPartialEq for Event<'input>

Auto Trait Implementations§

§

impl<'input> Freeze for Event<'input>

§

impl<'input> RefUnwindSafe for Event<'input>

§

impl<'input> Send for Event<'input>

§

impl<'input> Sync for Event<'input>

§

impl<'input> Unpin for Event<'input>

§

impl<'input> UnsafeUnpin for Event<'input>

§

impl<'input> UnwindSafe for Event<'input>

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.