Skip to main content

Kind

Enum Kind 

Source
#[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
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.
§

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

§

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)

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

Source

pub fn as_str(&self) -> &str

The name twig publishes for this kind — the exact string the C ABI’s TwigFlatNode.kind carries.

Source

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.

Trait Implementations§

Source§

impl Clone for Kind

Source§

fn clone(&self) -> Kind

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 Kind

Source§

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

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

impl Display for Kind

Source§

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

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

impl Eq for Kind

Source§

impl From<&str> for Kind

Source§

fn from(name: &str) -> Self

Converts to this type from the input type.
Source§

impl Hash for Kind

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Kind

Source§

fn eq(&self, other: &Kind) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Kind

Auto Trait Implementations§

§

impl Freeze for Kind

§

impl RefUnwindSafe for Kind

§

impl Send for Kind

§

impl Sync for Kind

§

impl Unpin for Kind

§

impl UnsafeUnpin for Kind

§

impl UnwindSafe for Kind

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.