pub trait HtmlEnv: Write + Sized {
// Provided methods
fn write_html(&mut self, html: impl Html) -> Result<&mut Self, Error> { ... }
fn doctype(&mut self) { ... }
fn write_html_text<'s>(&'s mut self) -> HtmlEscaper<'s, Self> { ... }
fn open_tag<'s, 't>(
&'s mut self,
tag: &'t str,
compactability: Compactability,
) -> Result<TagOpening<'s, 't, Self>, Error> { ... }
fn with_html_writer(
self,
f: impl FnOnce(&mut Self) -> Result,
) -> Result<Self, Error> { ... }
}
Expand description
Provided Methods§
Sourcefn write_html(&mut self, html: impl Html) -> Result<&mut Self, Error>
fn write_html(&mut self, html: impl Html) -> Result<&mut Self, Error>
Sourcefn doctype(&mut self)
fn doctype(&mut self)
Writes the HTML5 doctype.
§Example
use write_html::HtmlEnv;
let mut s = String::new();
s.doctype();
assert_eq!(s, "<!DOCTYPE html>");
Sourcefn write_html_text<'s>(&'s mut self) -> HtmlEscaper<'s, Self>
fn write_html_text<'s>(&'s mut self) -> HtmlEscaper<'s, Self>
Lets you write text into the HTML document, escaping it as necessary.
§Example
use write_html::HtmlEnv;
use std::fmt::Write;
let mut s = String::new();
s.write_html_text().write_str("Hello, <world>").unwrap();
assert_eq!(s, "Hello, <world>");
Sourcefn open_tag<'s, 't>(
&'s mut self,
tag: &'t str,
compactability: Compactability,
) -> Result<TagOpening<'s, 't, Self>, Error>
fn open_tag<'s, 't>( &'s mut self, tag: &'t str, compactability: Compactability, ) -> Result<TagOpening<'s, 't, Self>, Error>
Returns a tag opening, which lets you write attributes and inner HTML.
§Arguments
tag
- The tag name.compactability
- Whether the tag can be compacted.
§Example
use write_html::{HtmlEnv, Compactability};
use std::fmt::Write;
let mut s = String::new();
s.open_tag("h1", Compactability::No).unwrap()
.with_attr("id", "my-id").unwrap()
.inner_html().unwrap()
.write_str("Hello, world!").unwrap();
assert_eq!(s, "<h1 id=\"my-id\">Hello, world!</h1>");
fn with_html_writer( self, f: impl FnOnce(&mut Self) -> Result, ) -> Result<Self, Error>
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.