5use wasm_bindgen::UnwrapThrowExt;
7/// A trait for any component that can be rendered to HTML.
9/// Takes a shared reference to `self` and generates the virtual DOM that
10/// represents its rendered HTML.
12/// ## `Bump` Allocation
14/// `Render` implementations can use the provided `Bump` for very fast
15/// allocation for anything that needs to be allocated during rendering.
17/// ## The `'a: 'bump` Lifetime Bound
19/// The `'a: 'bump` bounds enforce that `self` outlives the given bump
20/// allocator. This means that if `self` contains a string, the string does not
21/// need to be copied into the output `Node` and can be used by reference
22/// instead (i.e. it prevents accidentally using the string after its been
23/// freed). The `'a: 'bump` bound also enables abstractions like
24/// `dodrio::Cached` that can re-use cached `Node`s across `render`s without
30/// use dodrio::{bumpalo::Bump, Node, Render};
32/// pub struct MyComponent;
34/// impl Render for MyComponent {
35/// fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
39/// Node::text("This is my component rendered!")
44 /// Render `self` as a virtual DOM. Use the given `Bump` for temporary
46 fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
51impl<'r, R> Render for &'r R
55 fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
63impl<R> Render for Rc<R>
67 fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
75/// A `RootRender` is a render component that can be the root rendering component
76/// mounted to a virtual DOM.
78/// In addition to rendering, it must also be `'static` so that it can be owned
79/// by the virtual DOM and `Any` so that it can be downcast to its concrete type
80/// by event listener callbacks.
82/// You do not need to implement this trait by hand: there is a blanket
83/// implementation for all `Render` types that fulfill the `RootRender`
85pub trait RootRender: Any + Render {
86 /// Get this `&RootRender` trait object as an `&Any` trait object reference.
87 fn as_any(&self) -> &Any;
89 /// Get this `&mut RootRender` trait object as an `&mut Any` trait object
91 fn as_any_mut(&mut self) -> &mut Any;
94impl<T: Any + Render> RootRender for T {
95 fn as_any(&self) -> &Any {
99 fn as_any_mut(&mut self) -> &mut Any {
105 /// Downcast this shared `&dyn RootRender` trait object reference to its
106 /// underlying concrete type.
110 /// Panics if this virtual DOM's root rendering component is not an `R`
112 pub fn unwrap_ref<R: RootRender>(&self) -> &R {
115 .expect_throw("bad `RootRender::unwrap_ref` call")
118 /// Downcast this exclusive `&mut dyn RootRender` trait object reference to
119 /// its underlying concrete type.
123 /// Panics if this virtual DOM's root rendering component is not an `R`
125 pub fn unwrap_mut<R: RootRender>(&mut self) -> &mut R {
128 .expect_throw("bad `RootRender::unwrap_ref` call")
135 fn render_is_object_safe() {
137 fn takes_dyn_render(_: &dyn super::Render) {}
141 fn root_render_is_object_safe() {
143 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