asciidoc_parser::blocks

Trait IsBlock

Source
pub trait IsBlock<'src>:
    HasSpan<'src>
    + Clone
    + Debug
    + Eq
    + PartialEq {
    // Required methods
    fn content_model(&self) -> ContentModel;
    fn context(&self) -> CowStr<'src>;

    // Provided method
    fn nested_blocks(&'src self) -> Iter<'src, Block<'src>> { ... }
}
Expand description

Block elements form the main structure of an AsciiDoc document, starting with the document itself.

A block element (aka block) is a discrete, line-oriented chunk of content in an AsciiDoc document. Once parsed, that chunk of content becomes a block element in the parsed document model. Certain blocks may contain other blocks, so we say that blocks can be nested. The converter visits each block in turn, in document order, converting it to a corresponding chunk of output.

This trait implements many of the same core methods as the Block enum but provides a mechanism for third-party code to extend the behavior of blocks.

Required Methods§

Source

fn content_model(&self) -> ContentModel

Returns the ContentModel for this block.

Source

fn context(&self) -> CowStr<'src>

Returns the context for this block.

A block’s context is also sometimes referred to as a name, such as an example block, a sidebar block, an admonition block, or a section.

Every block has a context. The context is often implied by the syntax, but can be declared explicitly in certain cases. The context is what distinguishes one kind of block from another. You can think of the context as the block’s type.

For that reason, the context is not defined as an enumeration, but rather as a string type that is optimized for the case where predefined constants are viable.

Provided Methods§

Source

fn nested_blocks(&'src self) -> Iter<'src, Block<'src>>

Returns an iterator over the nested blocks contained within this block.

Many block types do not have nested blocks so the default implementation returns an empty iterator.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'src> IsBlock<'src> for Block<'src>

Source§

impl<'src> IsBlock<'src> for Document<'src>

Source§

impl<'src> IsBlock<'src> for MacroBlock<'src>

Source§

impl<'src> IsBlock<'src> for RawDelimitedBlock<'src>

Source§

impl<'src> IsBlock<'src> for SectionBlock<'src>

Source§

impl<'src> IsBlock<'src> for SimpleBlock<'src>