Skip to main content

StyleStack

Struct StyleStack 

Source
pub struct StyleStack { /* private fields */ }
Expand description

Stack of open inline-style spans with deferred starts and overlap normalization.

Construct with StyleStack::default. The typical reader loop is:

  1. On encountering an open-style marker, call StyleStack::open and enqueue the returned events.
  2. Before emitting any Event::Text, call StyleStack::note_text and enqueue the returned events (deferred StartTextStyle events are released here).
  3. On encountering a close-style marker, call StyleStack::close.
  4. At a block boundary, call StyleStack::close_all to auto-close any spans still open.

All four methods return the events the reader should emit, in order, for the current step. The stack itself never emits directly.

Implementations§

Source§

impl StyleStack

Source

pub fn open(&mut self, kind: TextStyleKind) -> Vec<Event>

Opens an inline style if it is not already active and depth allows it.

The corresponding Event::StartTextStyle is deferred — it is not returned here. It is released by the next StyleStack::note_text call, so an empty styled span (open immediately followed by close with no intervening text) emits no events. This implements Rule 13.

Opens are idempotent on kind: if a frame with an equal kind is already on the stack, this call is a no-op and returns an empty vector. Colour-bearing variants compare by colour, so opening Mark(red) while Mark(blue) is open does push a new frame.

Returns an empty vector in all cases; the signature returns Vec<Event> to match StyleStack::close and StyleStack::note_text for caller uniformity.

Source

pub fn close(&mut self, kind: &TextStyleKind) -> Vec<Event>

Closes an inline style, normalizing overlaps via close-and-reopen.

If kind is not currently open, the call is a no-op and returns an empty vector. When the matching frame is below other open frames in the stack (an overlap such as <b><i>x</b></i>), the frames above it are closed in LIFO order, the target frame is closed, and the previously-above frames are re-opened with their starts deferred again. This is the close-and-reopen pattern that satisfies Rule 9.

Returns the Event::EndTextStyle events that the caller should emit, in order. A frame whose text_emitted flag is false contributes no event — its deferred start was never released, so no matching end is needed (Rule 13).

Source

pub fn note_text(&mut self) -> Vec<Event>

Marks every open frame as having emitted text and releases all deferred Event::StartTextStyle events.

Callers invoke this immediately before emitting an Event::Text, Event::LineBreak, or any other event that constitutes “content under the currently open styles”. The returned events must be enqueued in order, before the content event.

Source

pub fn close_all(&mut self) -> Vec<Event>

Closes every active style from innermost to outermost, suppressing frames whose deferred start was never released.

Used at block boundaries (paragraph end, heading end, run end in OOXML, etc.) to satisfy Rule 10. After this call the stack is empty.

Source

pub fn is_empty(&self) -> bool

Returns true when no open frames and no deferred starts remain.

Trait Implementations§

Source§

impl Clone for StyleStack

Source§

fn clone(&self) -> StyleStack

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 StyleStack

Source§

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

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

impl Default for StyleStack

Source§

fn default() -> StyleStack

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.