Struct build_html::Container
source · [−]pub struct Container { /* private fields */ }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
sourceimpl Container
impl Container
sourcepub fn new(tag: ContainerType) -> Self
pub fn new(tag: ContainerType) -> Self
Creates a new container with the specified tag.
sourcepub fn with_attributes<A, S>(self, attributes: A) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
pub fn with_attributes<A, S>(self, attributes: A) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
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
sourceimpl Html for Container
impl Html for Container
sourcefn to_html_string(&self) -> String
fn to_html_string(&self) -> String
Convert this element into an HTML string Read more
sourceimpl HtmlContainer for Container
impl HtmlContainer for Container
sourcefn add_html<H: Html>(&mut self, content: H)
fn add_html<H: Html>(&mut self, content: H)
Adds the specified HTML element to this container Read more
sourcefn with_html<H: Html>(self, html: H) -> Self
fn with_html<H: Html>(self, html: H) -> Self
Consumes the container, returning it with the specified HTML element added to it Read more
sourcefn add_container(&mut self, container: Container)
fn add_container(&mut self, container: Container)
Add the container to this HTML Container Read more
sourcefn with_container(self, container: Container) -> Self
fn with_container(self, container: Container) -> Self
Nest the specified container within this container Read more
sourcefn with_table(self, table: Table) -> Self
fn with_table(self, table: Table) -> Self
Nest the specified Table within this container Read more
sourcefn add_header(&mut self, level: u8, text: impl ToString)
fn add_header(&mut self, level: u8, text: impl ToString)
Adds a header tag with the designated level to this container Read more
sourcefn with_header(self, level: u8, text: impl ToString) -> Self
fn with_header(self, level: u8, text: impl ToString) -> Self
Adds a header tag with the designated level to this container Read more
sourcefn add_header_attr<A, S>(&mut self, level: u8, text: impl ToString, attr: A) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn add_header_attr<A, S>(&mut self, level: u8, text: impl ToString, attr: A) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds a header tag with the designated level and attributes to this container. Read more
sourcefn with_header_attr<A, S>(self, level: u8, text: impl ToString, attr: A) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn with_header_attr<A, S>(self, level: u8, text: impl ToString, attr: A) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds a header tag with the designated level and attributes to this container. Read more
sourcefn add_image(&mut self, src: impl ToString, alt: impl ToString)
fn add_image(&mut self, src: impl ToString, alt: impl ToString)
Adds an <img> tag to this container Read more
sourcefn with_image(self, src: impl ToString, alt: impl ToString) -> Self
fn with_image(self, src: impl ToString, alt: impl ToString) -> Self
Adds an <img> tag to this container Read more
sourcefn add_image_attr<A, S>(&mut self, src: impl ToString, alt: impl ToString, attr: A) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn add_image_attr<A, S>(&mut self, src: impl ToString, alt: impl ToString, attr: A) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds an <img> tag with the specified attributes to this container Read more
sourcefn with_image_attr<A, S>(
self,
src: impl ToString,
alt: impl ToString,
attr: A
) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn with_image_attr<A, S>(
self,
src: impl ToString,
alt: impl ToString,
attr: A
) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds an <img> tag with the specified attributes to this container Read more
sourcefn add_link(&mut self, href: impl ToString, text: impl ToString)
fn add_link(&mut self, href: impl ToString, text: impl ToString)
Adds an <a> tag to this container Read more
sourcefn with_link(self, href: impl ToString, text: impl ToString) -> Self
fn with_link(self, href: impl ToString, text: impl ToString) -> Self
Adds an <a> tag to this container Read more
sourcefn add_link_attr<A, S>(
&mut self,
href: impl ToString,
text: impl ToString,
attr: A
) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn add_link_attr<A, S>(
&mut self,
href: impl ToString,
text: impl ToString,
attr: A
) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds an <a> tag with the specified attributes to this container Read more
sourcefn with_link_attr<A, S>(
self,
href: impl ToString,
text: impl ToString,
attr: A
) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn with_link_attr<A, S>(
self,
href: impl ToString,
text: impl ToString,
attr: A
) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds an <a> tag with the specified attributes to this container Read more
sourcefn add_paragraph(&mut self, text: impl ToString)
fn add_paragraph(&mut self, text: impl ToString)
Adds a <p> tag element to this Container Read more
sourcefn with_paragraph(self, text: impl ToString) -> Self
fn with_paragraph(self, text: impl ToString) -> Self
Adds a <p> tag element to this Container Read more
sourcefn add_paragraph_attr<A, S>(&mut self, text: impl ToString, attr: A) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn add_paragraph_attr<A, S>(&mut self, text: impl ToString, attr: A) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds a <p> tag element with the specified attributes to this Container Read more
sourcefn with_paragraph_attr<A, S>(self, text: impl ToString, attr: A) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn with_paragraph_attr<A, S>(self, text: impl ToString, attr: A) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds a <p> tag element with the specified attributes to this Container Read more
sourcefn add_preformatted(&mut self, text: impl ToString)
fn add_preformatted(&mut self, text: impl ToString)
Adds a <pre> tag element to this container Read more
sourcefn with_preformatted(self, text: impl ToString) -> Self
fn with_preformatted(self, text: impl ToString) -> Self
Adds a <pre> tag element to this container Read more
sourcefn add_preformatted_attr<A, S>(&mut self, text: impl ToString, attr: A) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn add_preformatted_attr<A, S>(&mut self, text: impl ToString, attr: A) where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds a <pre> tag element with the specified attributes to this container Read more
sourcefn with_preformatted_attr<A, S>(self, text: impl ToString, attr: A) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
fn with_preformatted_attr<A, S>(self, text: impl ToString, attr: A) -> Self where
A: IntoIterator<Item = (S, S)>,
S: ToString,
Adds a <pre> tag element with the specified attributes to this container Read more
Auto Trait Implementations
impl RefUnwindSafe for Container
impl Send for Container
impl Sync for Container
impl Unpin for Container
impl UnwindSafe for Container
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more