1use crate::{Node, RenderContext};
4use wasm_bindgen::UnwrapThrowExt;
6/// A trait for any component that can be rendered to HTML.
8/// Takes a shared reference to `self` and generates the virtual DOM that
9/// represents its rendered HTML.
11/// ## `Bump` Allocation
13/// `Render` implementations can use the `Bump` inside the provided
14/// `RenderContext` for very fast allocation for anything that needs to be
15/// temporarily allocated during rendering.
20/// use dodrio::{Node, Render, RenderContext};
22/// pub struct MyComponent;
24/// impl Render for MyComponent {
25/// fn render<'a>(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
26/// use dodrio::builder::*;
31/// strong(&cx).children([text("my component")]).finish(),
32/// text(" rendered!"),
39 /// Render `self` as a virtual DOM. Use the given context's `Bump` for
40 /// temporary allocations.
41 fn render<'a>(&self, cx: &mut RenderContext<'a>) -> Node<'a>;
44impl<'r, R> Render for &'r R
48 fn render<'a>(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
53impl<R> Render for Rc<R>
57 fn render<'a>(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
62/// A `RootRender` is a render component that can be the root rendering component
63/// mounted to a virtual DOM.
65/// In addition to rendering, it must also be `'static` so that it can be owned
66/// by the virtual DOM and `Any` so that it can be downcast to its concrete type
67/// by event listener callbacks.
69/// You do not need to implement this trait by hand: there is a blanket
70/// implementation for all `Render` types that fulfill the `RootRender`
72pub trait RootRender: Any + Render {
73 /// Get this `&RootRender` trait object as an `&Any` trait object reference.
74 fn as_any(&self) -> &Any;
76 /// Get this `&mut RootRender` trait object as an `&mut Any` trait object
78 fn as_any_mut(&mut self) -> &mut Any;
81impl<T> RootRender for T
85 fn as_any(&self) -> &Any {
89 fn as_any_mut(&mut self) -> &mut Any {
95 /// Downcast this shared `&dyn RootRender` trait object reference to its
96 /// underlying concrete type.
100 /// Panics if this virtual DOM's root rendering component is not an `R`
102 pub fn unwrap_ref<R>(&self) -> &R
108 .expect_throw("bad `RootRender::unwrap_ref` call")
111 /// Downcast this exclusive `&mut dyn RootRender` trait object reference to
112 /// its underlying concrete type.
116 /// Panics if this virtual DOM's root rendering component is not an `R`
118 pub fn unwrap_mut<R>(&mut self) -> &mut R
124 .expect_throw("bad `RootRender::unwrap_ref` call")
131 fn render_is_object_safe() {
133 fn takes_dyn_render(_: &dyn super::Render) {}
137 fn root_render_is_object_safe() {
139 fn takes_dyn_render(_: &dyn super::RootRender) {}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list