[−][src]Trait maud::Render
Represents a type that can be rendered as HTML.
If your type implements Display
, then it will implement this
trait automatically through a blanket impl.
On the other hand, if your type has a custom HTML representation,
then you can implement Render
by hand. To do this, override
either the .render()
or .render_to()
methods; since each is
defined in terms of the other, you only need to implement one of
them. See the example below.
Minimal implementation
An implementation of this trait must override at least one of
.render()
or .render_to()
. Since the default definitions of
these methods call each other, not doing this will result in
infinite recursion.
Example
use maud::{html, Markup, Render}; /// Provides a shorthand for linking to a CSS stylesheet. pub struct Stylesheet(&'static str); impl Render for Stylesheet { fn render(&self) -> Markup { html! { link rel="stylesheet" type="text/css" href=(self.0); } } }
Provided methods
pub fn render(&self) -> Markup
[src]
Renders self
as a block of Markup
.
pub fn render_to(&self, buffer: &mut String)
[src]
Appends a representation of self
to the given buffer.
Its default implementation just calls .render()
, but you may
override it with something more efficient.
Note that no further escaping is performed on data written to
the buffer. If you override this method, you must make sure that
any data written is properly escaped, whether by hand or using
the Escaper
wrapper struct.