#[non_exhaustive]pub enum Kind {
Show 61 variants
Doc,
Para,
Heading,
ThematicBreak,
Section,
CodeBlock,
RawBlock,
Metadata,
BlockQuote,
BulletList,
OrderedList,
TaskList,
DefinitionList,
LineBlock,
Table,
ListItem,
TaskListItem,
DefinitionListItem,
Term,
Definition,
Line,
Row,
Cell,
Column,
Caption,
Footnote,
Reference,
Citation,
Substitution,
Str,
SoftBreak,
HardBreak,
NonBreakingSpace,
RawInline,
SmartPunctuation,
Link,
Image,
Emph,
Strong,
Mark,
Superscript,
Subscript,
Insert,
Delete,
DoubleQuoted,
SingleQuoted,
Symb,
Verbatim,
InlineMath,
DisplayMath,
Url,
Email,
FootnoteReference,
CitationReference,
SubstitutionReference,
Container,
ProcessingInstruction,
Comment,
Doctype,
Cdata,
Other(String),
}Expand description
A node’s kind, as the shared vocabulary publishes it.
A typed enum rather than the String this used to be, because the string
made a whole class of upstream change invisible here. When twig collapsed
its four generic container kinds (div, span, directive, element)
into one container, every site in this crate that compared a kind name
kept compiling and started being wrong at runtime. With this, each of those
sites is a compile error pointing at the exact line.
#[non_exhaustive], and with an Other arm, for the two
different ways the vocabulary can outrun a given build of this crate:
#[non_exhaustive] makes ADDING a variant here a non-breaking change for
callers, and Other carries a name the linked library published that this
crate has no variant for at all. Match with a _ arm.
§What is one variant here and two in the core
The nine inline marks share a single inline_mark kind in twig’s own AST,
and the nine text leaves share a single text_leaf; both publish their
MEMBER name ("superscript", not "inline_mark"). This enum follows the
published vocabulary, so they are variants here — the grouping is an
implementation detail of the core, not something a consumer should have to
know.
§No PartialEq<&str>
Deliberately absent, though it would be one impl and would keep every
node.kind == Kind::Image in existing code compiling. That is precisely the
property this type exists to remove: a comparison against a string literal
is exactly what survived the container rename and went silently wrong.
Compare against a variant; reach for as_str only when you
genuinely want the name (logging it, or forwarding it to something that
speaks the wire vocabulary).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Doc
Para
Heading
ThematicBreak
Section
CodeBlock
RawBlock
Metadata
BlockQuote
BulletList
OrderedList
TaskList
DefinitionList
LineBlock
Table
ListItem
TaskListItem
DefinitionListItem
Term
Definition
Line
Row
Cell
Column
Caption
Footnote
Reference
Citation
Substitution
Str
SoftBreak
HardBreak
NonBreakingSpace
RawInline
SmartPunctuation
Link
Image
Emph
Strong
Mark
Superscript
Subscript
Insert
Delete
DoubleQuoted
SingleQuoted
Symb
Verbatim
InlineMath
DisplayMath
Url
FootnoteReference
CitationReference
SubstitutionReference
Container
ProcessingInstruction
Comment
Doctype
Cdata
Other(String)
A kind name the linked library published that this crate has no variant for — a newer twig against an older binding.
Deliberately not an error: a node whose kind this crate cannot name is still a node with a span, children and attributes, and a renderer that wants to pass it through unchanged should not be stopped from doing so.
Implementations§
Source§impl Kind
impl Kind
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
The name twig publishes for this kind — the exact string the C ABI’s
TwigFlatNode.kind carries.
Sourcepub fn is_unknown(&self) -> bool
pub fn is_unknown(&self) -> bool
Whether this is a kind the linked library named and this crate could
not — the Other case, and the one worth logging when a
renderer meets a node it has no arm for.