#[non_exhaustive]pub enum Event<'input> {
Show 13 variants
StreamStart,
StreamEnd,
DocumentStart(bool, Option<YamlVersion>),
DocumentEnd,
Alias(usize),
Anchor(usize, Cow<'input, str>),
UnresolvedAlias(Cow<'input, str>),
Comment(Cow<'input, str>, Placement),
Scalar(Cow<'input, str>, ScalarStyle, usize, Option<Cow<'input, Tag>>),
SequenceStart(StructureStyle, usize, Option<Cow<'input, Tag>>),
SequenceEnd,
MappingStart(StructureStyle, usize, Option<Cow<'input, Tag>>),
MappingEnd,
}Expand description
An event generated by the YAML parser.
Events are used in the low-level event-based API (push parser). The API entrypoint is the
EventReceiver trait.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
StreamStart
Event generated at the very beginning of parsing.
StreamEnd
Last event that will be generated by the parser. Signals EOF.
DocumentStart(bool, Option<YamlVersion>)
The start of a YAML document.
Tuple Fields
0: boolWhether this is an explicit document start marker (---).
When false, the document start is implicit.
1: Option<YamlVersion>YAML version declared by a preceding %YAML directive, if any.
DocumentEnd
The end of a YAML document.
This event is emitted for both explicit document end markers (...) and implicit document
ends.
Alias(usize)
A resolved YAML alias.
The companion Span covers the complete *name token, preserving the original name
through its source range. With Options::emit_anchor_events, Self::Anchor connects
the target ID to its definition’s name and source range.
Anchor(usize, Cow<'input, str>)
Metadata for an anchor definition on the immediately preceding node in its parser’s stream.
Emitted only when Options::emit_anchor_events is true, immediately after the
anchored Self::Scalar, Self::SequenceStart, or Self::MappingStart, before any
collection children. This is presentation metadata, not an additional YAML node.
The companion Span covers the complete &name token, whose source position precedes
the node content. Comments between properties and content can precede the node event.
Emitting the node first ensures that a failure before its event is emitted cannot leave
anchor metadata without an associated node event, even during document recovery.
This adjacency guarantee applies to an individual Parser. See crate::ParserStack
for ordering when sources are interleaved.
Repeated names receive distinct IDs; aliases refer to the most recent preceding
definition in the same document. IDs match those on node and Self::Alias events,
including when Parser::set_anchor_offset is used.
Tuple Fields
UnresolvedAlias(Cow<'input, str>)
An alias without a preceding anchor definition in its document.
Emitted only when Options::emit_unresolved_aliases is true. The companion Span
covers the complete alias token, including *. This event occupies a node position but
represents an invalid reference; a later anchor definition does not resolve it retroactively.
Comment(Cow<'input, str>, Placement)
A YAML source comment.
Comments are presentation metadata, not YAML data nodes. The payload is the raw text
exactly after #, excluding only the line break. The placement is a best-effort hint for
correlating the comment with nearby YAML presentation. The companion parser Span covers
the whole source comment, including # and excluding the line break.
Tuple Fields
Scalar(Cow<'input, str>, ScalarStyle, usize, Option<Cow<'input, Tag>>)
A YAML scalar value.
Tuple Fields
1: ScalarStyleThe source notation used for the scalar.
SequenceStart(StructureStyle, usize, Option<Cow<'input, Tag>>)
The start of a YAML sequence (array).
Tuple Fields
0: StructureStyleThe notation style used for the sequence.
SequenceEnd
The end of a YAML sequence (array).
MappingStart(StructureStyle, usize, Option<Cow<'input, Tag>>)
The start of a YAML mapping (object, hash).
Tuple Fields
0: StructureStyleThe notation style used for the mapping (Flow or Block).
MappingEnd
The end of a YAML mapping (object, hash).
Implementations§
Source§impl<'input> Event<'input>
impl<'input> Event<'input>
Sourcepub fn anchor_id(&self) -> Option<usize>
pub fn anchor_id(&self) -> Option<usize>
Return the anchor ID defined by this event, if any.
Returns Some(id) when this event defines an anchor on a scalar, sequence, or mapping
node, or describes that definition with Self::Anchor. The reserved ID 0 returns
None. Returns None for all other events, including resolved and unresolved aliases
(which reference anchors rather than defining them; use Self::alias_id to obtain a
resolved target anchor ID).
To count anchored nodes once, also require Self::is_node, since Self::Anchor
repeats the node’s ID.
Sourcepub fn alias_id(&self) -> Option<usize>
pub fn alias_id(&self) -> Option<usize>
Return the target anchor ID if this event is a resolved alias.
Returns None for unresolved aliases and non-alias events. Use Self::is_alias to
recognize either kind of alias, or match Self::UnresolvedAlias to obtain its name.
Sourcepub fn scalar(&self) -> Option<(&str, ScalarStyle)>
pub fn scalar(&self) -> Option<(&str, ScalarStyle)>
Return the scalar value and style, if this event is a scalar.
Sourcepub fn is_node(&self) -> bool
pub fn is_node(&self) -> bool
Return whether this event represents a YAML node (value).
Returns true for scalars, collection starts, and resolved or unresolved aliases, all of
which occupy a node position. Returns false for structural events such as StreamStart,
DocumentStart, collection ends, and presentation metadata such as Self::Anchor.