Skip to main content

Event

Enum Event 

Source
#[non_exhaustive]
pub enum Event {
Show 42 variants EndBlockQuote, EndCaption, EndDefinitionDetail, EndDefinitionList, EndDefinitionTerm, EndDocument, EndFootnote, EndHeading, EndLink, EndOrderedListItem, EndParagraph, EndPreformatted, EndTable, EndTableCell, EndTableHeader, EndTableRow, EndTextStyle, EndUnorderedListItem, FootnoteRef { id: u32, }, Image { alt: Option<String>, decorative: bool, id: Option<String>, source: ImageSource, title: Option<String>, }, LineBreak, SoftBreak, StartBlockQuote { id: Option<String>, }, StartCaption { id: Option<String>, }, StartDefinitionDetail { id: Option<String>, }, StartDefinitionList { id: Option<String>, }, StartDefinitionTerm { id: Option<String>, }, StartDocument { id: Option<String>, language: Option<String>, metadata: Option<DocumentMeta>, }, StartFootnote { id: u32, }, StartHeading { id: Option<String>, level: u8, }, StartLink { href: String, id: Option<String>, title: Option<String>, }, StartOrderedListItem { id: Option<String>, level: u32, start: Option<u64>, style_type: ListStyleType, }, StartParagraph { alignment: Option<TextAlignment>, id: Option<String>, }, StartPreformatted { id: Option<String>, syntax: Option<String>, }, StartTable { id: Option<String>, }, StartTableCell { colspan: Option<u32>, id: Option<String>, rowspan: Option<u32>, }, StartTableHeader { abbr: Option<String>, colspan: Option<u32>, id: Option<String>, rowspan: Option<u32>, scope: Option<TableHeaderScope>, }, StartTableRow { id: Option<String>, }, StartTextStyle { kind: TextStyleKind, id: Option<String>, }, StartUnorderedListItem { id: Option<String>, level: u32, style_type: ListStyleType, }, Text { content: String, }, ThematicBreak { id: Option<String>, },
}
Expand description

A streaming document event.

Events flow from crate::EventSource readers to crate::EventSink writers. The enum is marked #[non_exhaustive] to allow adding new event types in future versions; downstream consumers must include a wildcard _ => arm when matching.

Events come in three categories:

  • Start/End pairs: Container elements like headings, paragraphs, tables. Every Start* has exactly one matching End* (Rule 1 in module docs).
  • Self-contained: Standalone elements like text, images, line breaks.
  • Block vs Inline: Block events create new vertical sections; inline events flow within blocks.

See the module-level documentation for error handling, asset references, and the full well-formedness ruleset.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

EndBlockQuote

End a block quote.

§

EndCaption

End a table caption.

§

EndDefinitionDetail

End a definition detail.

§

EndDefinitionList

End a definition list.

§

EndDefinitionTerm

End a definition term.

§

EndDocument

End a document.

§

EndFootnote

End a footnote definition.

§

EndHeading

End a heading.

End a hyperlink.

§

EndOrderedListItem

End an ordered (numbered) list item.

§

EndParagraph

End a paragraph.

§

EndPreformatted

End a preformatted block.

§

EndTable

End a table.

§

EndTableCell

End a table data cell.

§

EndTableHeader

End a table header cell.

§

EndTableRow

End a table row.

§

EndTextStyle

End an inline text style span.

§

EndUnorderedListItem

End an unordered (bulleted) list item.

§

FootnoteRef

A reference to a footnote.

Inline marker; the corresponding Event::StartFootnote definition appears elsewhere in the stream (before or after this reference, depending on source format). Each footnote ID appears in exactly one FootnoteRef and one Event::StartFootnote (Rule 7 in module docs).

Fields

§id: u32

The footnote identifier being referenced.

§

Image

An image reference.

Asset bytes resolve lazily via crate::AssetProvider. decorative means purely visual — no alt text is needed for accessibility. Images may appear inline within paragraphs/headings or directly in block containers.

Fields

§alt: Option<String>

Alternative text for accessibility.

§decorative: bool

Whether the image is purely decorative (no alt text needed).

§id: Option<String>

Optional block identifier for the image.

§source: ImageSource

Source of the image (embedded asset or external URI).

§title: Option<String>

Optional tooltip text.

§

LineBreak

A hard line break within a paragraph.

Explicit hard break (e.g., markdown two-space-newline, HTML <br>).

§

SoftBreak

A soft line break in source markup, such as a markdown line wrap.

Soft breaks correspond to source line wraps that do not enforce a visible break. Writers choose rendering policy: space, newline, <br>, etc.

§

StartBlockQuote

Begin a block quote.

May contain any block element.

Fields

§id: Option<String>

Optional block identifier.

§

StartCaption

Begin a table caption.

Appears at most once per table, before any rows (Rule 6 in module docs).

Fields

§id: Option<String>

Optional block identifier.

§

StartDefinitionDetail

Begin a definition detail (description).

Details can contain any block element.

Fields

§id: Option<String>

Optional block identifier.

§

StartDefinitionList

Begin a definition list.

Contains Event::StartDefinitionTerm / Event::StartDefinitionDetail pairs.

Fields

§id: Option<String>

Optional block identifier.

§

StartDefinitionTerm

Begin a definition term.

Terms contain inline content only.

Fields

§id: Option<String>

Optional block identifier.

§

StartDocument

Begin a document with optional language and metadata.

The root container — exactly one per stream (Rule 2 in module docs). language is a BCP 47 tag (e.g., "en", "en-US", "zh-Hans").

Fields

§id: Option<String>

Optional block identifier.

§language: Option<String>

BCP 47 language tag (e.g., “en”, “en-US”, “zh-Hans”).

§metadata: Option<DocumentMeta>

Document metadata including title, authors, and description.

§

StartFootnote

Begin a footnote definition.

Readers emit StartFootnote as soon as practical; placement varies by source format. The corresponding Event::FootnoteRef may appear before or after this definition. Writers decide final placement and must buffer if needed. Footnotes contain paragraphs only; this restriction may relax in future versions.

Fields

§id: u32

Unique identifier for this footnote.

§

StartHeading

Begin a heading of the given level.

Levels 1–6 are standard (HTML). DOCX/ODT/RTF support 1–9. Writers clamp higher levels to their format’s maximum. Heading levels are 1-based (range 1–9); list item level (on Event::StartOrderedListItem and Event::StartUnorderedListItem) is 0-indexed.

Fields

§id: Option<String>

Optional block identifier for the heading.

§level: u8

Heading level, 1–9 (1 is most prominent).

Begin a hyperlink.

An inline container (uses Start/End because it carries href). Valid inside paragraphs, headings, list items, cells, and definition details. Links do not nest (Rule 4 in module docs).

Fields

§href: String

URL or URI target of the link.

§id: Option<String>

Optional block identifier.

§title: Option<String>

Optional tooltip text.

§

StartOrderedListItem

Begin an ordered (numbered) list item.

See Event::StartUnorderedListItem for nesting and list-boundary semantics — they apply identically here. start is populated only on the first item of an ordered list; subsequent items use None.

Fields

§id: Option<String>

Optional block identifier.

§level: u32

Zero-indexed nesting depth (0 = top-level list).

§start: Option<u64>

Starting number for the list, populated only on the first item of an ordered list (subsequent items in the same list: None).

§style_type: ListStyleType

Visual style of the list marker. Writers tolerate mismatches per ListStyleType convention.

§

StartParagraph

Begin a paragraph with optional alignment.

Fields

§alignment: Option<TextAlignment>

Text alignment for the paragraph.

§id: Option<String>

Optional block identifier for the paragraph.

§

StartPreformatted

Begin a preformatted (code) block with optional syntax highlighting.

Inside StartPreformatted/Event::EndPreformatted, no Event::StartTextStyle events appear (Rule 11 in module docs). When syntax is present, the block has code semantics. Newlines in content are literal.

Fields

§id: Option<String>

Optional block identifier.

§syntax: Option<String>

Language identifier for syntax highlighting (e.g., “rust”, “python”).

§

StartTable

Begin a table.

Contains an optional Event::StartCaption (at most one, before any rows), then Event::StartTableRow events. Cells may contain any block element.

Fields

§id: Option<String>

Optional block identifier.

§

StartTableCell

Begin a table data cell.

Data cells omit the scope and abbr fields carried by Event::StartTableHeader; use the header variant for cells that describe other cells.

Fields

§colspan: Option<u32>

Number of columns this cell spans.

§id: Option<String>

Optional block identifier.

§rowspan: Option<u32>

Number of rows this cell spans.

§

StartTableHeader

Begin a table header cell.

Header cells carry scope and abbr for accessibility; data cells (use Event::StartTableCell) omit these.

Fields

§abbr: Option<String>

Abbreviated content for accessibility.

§colspan: Option<u32>

Number of columns this cell spans.

§id: Option<String>

Optional block identifier.

§rowspan: Option<u32>

Number of rows this cell spans.

§scope: Option<TableHeaderScope>

Whether this header applies to a column or row.

§

StartTableRow

Begin a table row.

Fields

§id: Option<String>

Optional block identifier.

§

StartTextStyle

Begin an inline text style span.

Valid inside paragraphs, headings, list items, cells, and definition details. Style spans nest but never overlap (Rules 1 and 9 in module docs); readers MUST close-and-reopen to express overlapping source styles. The TextStyleKind::Mark variant carries the highlight color; TextStyleKind::TextColor carries the foreground text color.

Fields

§kind: TextStyleKind

The style kind opened by this span.

§id: Option<String>

Optional block identifier for the style span.

§

StartUnorderedListItem

Begin an unordered (bulleted) list item.

Child items nest inside the parent’s Start*/End* pair; the parent’s Event::EndUnorderedListItem appears AFTER all children and any continuation content (paragraphs, line breaks) belonging to the parent. level is 0-indexed and authoritative — writers may rely on it alone.

List boundaries (applies to Event::StartOrderedListItem as well): a new list begins when (a) a non-list block intervenes, (b) ordered vs. unordered changes at the same level, or (c) level decreases then increases without a parent.

Fields

§id: Option<String>

Optional block identifier.

§level: u32

Zero-indexed nesting depth (0 = top-level list).

§style_type: ListStyleType

Visual style of the list marker. Writers tolerate mismatches per ListStyleType convention.

§

Text

A text run.

Whitespace is significant. Outside preformatted blocks, newlines in content are collapsed to whitespace; readers emit Event::LineBreak for explicit hard breaks (e.g., markdown two-space-newline, HTML <br>) and Event::SoftBreak for soft breaks (e.g., source line wraps within a paragraph). Inline formatting is expressed via surrounding Event::StartTextStyle/Event::EndTextStyle wrapper events; the Text event itself carries content only.

Fields

§content: String

The text content.

§

ThematicBreak

A horizontal rule / thematic break.

Section separator. Self-contained block event.

Fields

§id: Option<String>

Optional block identifier.

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

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 Debug for Event

Source§

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

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

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> 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 Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

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.