domafic-rs
domafic-rs copied to clipboard
Allow output of `Renderer` to reference bits of the application state
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>;
}