Trait maud::Render

source ·
pub trait Render {
    // Provided methods
    fn render(&self) -> Markup { ... }
    fn render_to(&self, buffer: &mut String) { ... }
}
Expand description

Represents a type that can be rendered as HTML.

To implement this for your own type, 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§

source

fn render(&self) -> Markup

Renders self as a block of Markup.

source

fn render_to(&self, buffer: &mut String)

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.

Implementations on Foreign Types§

source§

impl Render for char

source§

fn render_to(&self, w: &mut String)

source§

impl Render for f32

source§

fn render_to(&self, w: &mut String)

source§

impl Render for f64

source§

fn render_to(&self, w: &mut String)

source§

impl Render for i8

source§

fn render_to(&self, w: &mut String)

source§

impl Render for i16

source§

fn render_to(&self, w: &mut String)

source§

impl Render for i32

source§

fn render_to(&self, w: &mut String)

source§

impl Render for i64

source§

fn render_to(&self, w: &mut String)

source§

impl Render for i128

source§

fn render_to(&self, w: &mut String)

source§

impl Render for isize

source§

fn render_to(&self, w: &mut String)

source§

impl Render for str

source§

fn render_to(&self, w: &mut String)

source§

impl Render for u8

source§

fn render_to(&self, w: &mut String)

source§

impl Render for u16

source§

fn render_to(&self, w: &mut String)

source§

impl Render for u32

source§

fn render_to(&self, w: &mut String)

source§

impl Render for u64

source§

fn render_to(&self, w: &mut String)

source§

impl Render for u128

source§

fn render_to(&self, w: &mut String)

source§

impl Render for usize

source§

fn render_to(&self, w: &mut String)

source§

impl Render for String

source§

fn render_to(&self, w: &mut String)

source§

impl<'a> Render for Cow<'a, str>

source§

fn render_to(&self, w: &mut String)

source§

impl<'a> Render for Arguments<'a>

source§

fn render_to(&self, w: &mut String)

source§

impl<'a, T: Render + ?Sized> Render for &'a T

source§

fn render_to(&self, w: &mut String)

source§

impl<'a, T: Render + ?Sized> Render for &'a mut T

source§

fn render_to(&self, w: &mut String)

source§

impl<T: Render + ?Sized> Render for Box<T>

source§

fn render_to(&self, w: &mut String)

source§

impl<T: Render + ?Sized> Render for Arc<T>

source§

fn render_to(&self, w: &mut String)

Implementors§