[][src]Trait dodrio::Render

pub trait Render {
    fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
    where
        'a: 'bump
; }

A trait for any component that can be rendered to HTML.

Takes a shared reference to self and generates the virtual DOM that represents its rendered HTML.

Bump Allocation

Render implementations can use the provided Bump for very fast allocation for anything that needs to be allocated during rendering.

The 'a: 'bump Lifetime Bound

The 'a: 'bump bounds enforce that self outlives the given bump allocator. This means that if self contains a string, the string does not need to be copied into the output Node and can be used by reference instead (i.e. it prevents accidentally using the string after its been freed). The 'a: 'bump bound also enables abstractions like dodrio::Cached that can re-use cached Nodes across renders without copying them.

Example

use dodrio::{bumpalo::Bump, Node, Render};

pub struct MyComponent;

impl Render for MyComponent {
    fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
    where
        'a: 'bump
    {
        use dodrio::builder::*;

        p(bump)
            .children([
                text("This is "),
                strong(bump).children([text("my component")]).finish(),
                text(" rendered!"),
            ])
            .finish()
    }
}

Required methods

fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump> where
    'a: 'bump, 

Render self as a virtual DOM. Use the given Bump for temporary allocations.

Loading content...

Implementations on Foreign Types

impl<'r, R> Render for &'r R where
    R: Render
[src]

impl<R> Render for Rc<R> where
    R: Render
[src]

Loading content...

Implementors

impl<R: Render> Render for Cached<R>[src]

Loading content...