Struct build_html::Container[][src]

pub struct Container { /* fields omitted */ }
Expand description

A container for HTML elements.

As the name would suggest, a Container contains other HTML elements. This struct guarantees that the elements added will be converted to HTML strings in the same order as they were added.

Supported container types are provided by the ContainerType enum.

Note that Container elements can be nested inside of each other.

let text = Container::new(ContainerType::Main)
    .with_header(1, "My Container")
    .with_container(
        Container::new(ContainerType::Article)
            .with_container(
                Container::new(ContainerType::Div)
                    .with_paragraph("Inner Text")
            )
    )
    .to_html_string();

assert_eq!(
    text,
    "<main><h1>My Container</h1><article><div><p>Inner Text</p></div></article></main>"
);

Implementations

Creates a new container with the specified tag.

Associates the specified map of attributes with this Container.

Note that this operation overrides all previous with_attribute calls on this Container

Example

let container = Container::default()
    .with_attributes(vec![("class", "defaults")])
    .with_paragraph("text")
    .to_html_string();

assert_eq!(container, r#"<div class="defaults"><p>text</p></div>"#)

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Convert this element into an HTML string Read more

Adds the specified HTML element to this container Read more

Consumes the container, returning it with the specified HTML element added to it Read more

Add the container to this HTML Container Read more

Nest the specified container within this container Read more

Add the specified Table to this container Read more

Nest the specified Table within this container Read more

Adds a header tag with the designated level to this container Read more

Adds a header tag with the designated level to this container Read more

Adds a header tag with the designated level and attributes to this container. Read more

Adds a header tag with the designated level and attributes to this container. Read more

Adds an <img> tag to this container Read more

Adds an <img> tag to this container Read more

Adds an <img> tag with the specified attributes to this container Read more

Adds an <img> tag with the specified attributes to this container Read more

Adds an <a> tag to this container Read more

Adds an <a> tag to this container Read more

Adds an <a> tag with the specified attributes to this container Read more

Adds an <a> tag with the specified attributes to this container Read more

Adds a <p> tag element to this Container Read more

Adds a <p> tag element to this Container Read more

Adds a <p> tag element with the specified attributes to this Container Read more

Adds a <p> tag element with the specified attributes to this Container Read more

Adds a <pre> tag element to this container Read more

Adds a <pre> tag element to this container Read more

Adds a <pre> tag element with the specified attributes to this container Read more

Adds a <pre> tag element with the specified attributes to this container Read more

Add raw content to the container. This content is pasted directly into the HTML Read more

Add raw content to this container. The content is pasted directly into the HTML Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.