Skip to content

Allow output of Renderer to reference bits of the application state #1

@cramertj

Description

@cramertj

This would save a bunch of unnecessary allocations, and it is entirely safe since the state can't be modified between Renderer::render being called and the DomNode being drawn to the page. However, I don't think this is possible without ATCs, as the lifetime of the returned DomNode would be dependent upon the lifetime of the reference to the application state.

The modified Renderer trait might look something like this:

pub trait Renderer<State> {
    /// Type of the rendered `DomNode`
    type Rendered<'a>: DomNode + 'a;

    /// Renders a `DomNode` given the current application state
    fn render<'a>(&'a self, &'a State) -> Self::Rendered<'a>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions