Skip to main content

Container

Enum Container 

Source
pub enum Container {
    ListItem {
        ordered: bool,
        start: u64,
        ordinal: u64,
        instance: u64,
    },
    Quote {
        instance: u64,
    },
}
Expand description

A container a line nests inside. The ancestor path is a Vec<Container>.

Closed, on LineKind’s terms: a container outside this set is ParseError::UnknownName.

Variants§

§

ListItem

A list item. ordered distinguishes 1. from -; start is the list’s first number (1 by default); ordinal is this item’s 0-based index in its list; instance tells this list from an adjacent one of the same shape (see Container::instance).

Two adjacent lines belong to the same item iff their whole container path is equal. Identity is path plus contiguity: two sibling inner lists under one outer item can produce equal first-item paths, distinguished only by the non-adjacency of their runs.

Fields

§ordered: bool
§start: u64
§ordinal: u64
§instance: u64
§

Quote

A block quote. Adjacent lines sharing one Quote are one multi-paragraph quote; two adjacent quotes differ in instance.

Fields

§instance: u64

Implementations§

Source§

impl Container

Source

pub fn instance(&self) -> u64

Which instance of its shape this container is, among a run of adjacent siblings that would otherwise be indistinguishable.

Container identity is path plus contiguity, so two adjacent runs of equal shape read as one: [Quote], [Quote] is one quote, and two one-item lists are one item spanning two paragraphs. instance is the one field that exists to break that tie, and it is the whole reason the encoding is complete rather than a quotient.

A producer writes it against same_run: two adjacent runs of one shape need distinct values, whatever they are, or they arrive as one container. Content::normalize collapses those to the canonical pair — 0, flipping to 1 only where the projection would otherwise weld the two — so a document needing no discriminator carries none and one that needs it alternates 0, 1, 0, 1. Non-adjacent runs never collide, so two values suffice.

Source

pub fn tag(&self) -> &'static str

The wire container name.

Source

pub fn attrs(&self) -> Cow<'_, JsonValue>

The payload bag, one spelling for every member of the vocabulary. instance is not in it: it is an envelope key, carried on every arm.

Source

pub fn same_run(&self, other: &Container) -> bool

Whether these two are the same container shape, ordinal and instance aside — start counts, so a list starting at 1 and one starting at 3 are two shapes.

The identity rule, read and written alike: two adjacent lines sit in one container instance iff this holds and their instances are equal. crate::traverse::runs applies it, and a producer separates its runs against it. Whether the projection can then tell two runs apart is same_weld.

Source

pub fn same_weld(&self, other: &Container) -> bool

Whether the Markdown projection would read two adjacent runs of these shapes as one — that is, whether the canonical form must spend an instance to keep them apart. Content::normalize mints against this; same_run is what a producer writes against.

Coarser than same_run for lists, because start is invisible in Markdown: CommonMark reads only a list’s first number, so 1. a beside 3. b re-imports as one list of two items and the second list’s start is lost. Comparing ordered alone mints the discriminator there too, and the marker alternation carries it.

Trait Implementations§

Source§

impl Clone for Container

Source§

fn clone(&self) -> Container

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 Container

Source§

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

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

impl PartialEq for Container

Source§

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

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.