heart_patched_maud

Trait 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 Cow<'_, str>

Source§

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

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 Render for Arguments<'_>

Source§

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

Source§

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

Source§

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

Source§

impl<T: Render + ?Sized> Render for &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§