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:
- On encountering an open-style marker, call
StyleStack::openand enqueue the returned events. - Before emitting any
Event::Text, callStyleStack::note_textand enqueue the returned events (deferredStartTextStyleevents are released here). - On encountering a close-style marker, call
StyleStack::close. - At a block boundary, call
StyleStack::close_allto 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
impl StyleStack
Sourcepub fn open(&mut self, kind: TextStyleKind) -> Vec<Event>
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.
Sourcepub fn close(&mut self, kind: &TextStyleKind) -> Vec<Event>
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).
Sourcepub fn note_text(&mut self) -> Vec<Event>
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.
Trait Implementations§
Source§impl Clone for StyleStack
impl Clone for StyleStack
Source§fn clone(&self) -> StyleStack
fn clone(&self) -> StyleStack
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more