Skip to main content

Format

Enum Format 

Source
#[non_exhaustive]
pub enum Format { Djot, Markdown, Xml, Html, Asciidoc, }
Expand description

Every format Twig can parse — the input axis, as opposed to Target, which is where output bytes can go.

#[non_exhaustive] for the same reason Target is: Twig’s parser list grows (reStructuredText is written and awaiting a registry entry), and a caller matching on this enum should not have to be recompiled to keep compiling. Match with a _ arm.

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.
§

Djot

§

Markdown

§

Xml

§

Html

§

Asciidoc

Parsed and rendered, but not serialized: Target::Asciidoc reports Error::UnsupportedFormat, and no Editor gesture applies to an AsciiDoc document.

The parser also covers a slice of AsciiDoc rather than all of it — the header, paragraphs, sections, lists, delimited blocks and the inline spans. What it does not implement survives as literal source text rather than failing the parse, so a successful parse is not by itself a claim that the whole document was understood.

Implementations§

Source§

impl Format

Source

pub fn supports(self, gesture: Gesture) -> bool

Whether this format can spell gesture — the toolbar’s gray-out question, answered without a document, so a caller can build its UI before it has one. Pure and cheap: ask at startup and cache.

true means the gesture will not fail with Error::UnsupportedFormat. It is not a promise the call succeeds — the caret still decides, so a supported gesture can still report Error::NotFound, Error::NotEditable or Error::EditConflict at the position it is actually run. Gray out on false; do not read true as “this will work here”.

Returns a plain bool rather than a Result because the two ways the C query can fail — an unknown format code, a kind from the wrong vocabulary — are both unrepresentable here: Format and Gesture are enums, and a Gesture carries a kind only where one applies.

Distinct from BOTH neighbouring questions:

  • Format::is_authorable is “is there a door in”, true for Format::Html on its inline marks alone.
  • Warning::fidelity is “what survives a conversion to this target”, which is a different table with genuinely different answers — Djot round-trips a smart-quote container faithfully while no editor gesture may author one. Use that for a save-as warning, this for a button.
Source

pub fn is_authorable(self) -> bool

Whether this format can be authored into at allfalse for a parse-only format (Format::Xml, Format::Asciidoc), where every gesture refuses and an editor should offer no toolbar. The open-read-only question.

true is a weaker claim than it looks, and driving per-button state from it is the mistake this doc exists to prevent: Format::Html answers true — it spells the inline marks — while Gesture::SetBlock, the container, code-block, task and footnote gestures and Gesture::InsertLiteral are all still unsupported there. Use Format::supports per button.

Trait Implementations§

Source§

impl Clone for Format

Source§

fn clone(&self) -> Format

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 Copy for Format

Source§

impl Debug for Format

Source§

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

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

impl Eq for Format

Source§

impl From<Format> for TwigFormat

Source§

fn from(value: Format) -> Self

Converts to this type from the input type.
Source§

impl From<Format> for Target

Total: every input format is also an output target, even the ones with no serializer yet (converting into XML reports Error::UnsupportedFormat rather than being unnameable).

Source§

fn from(value: Format) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Format

Source§

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

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.