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/// use dodrio::builder::*;
44/// strong(bump).children([text("my component")]).finish(),
45/// text(" rendered!"),
52 /// Render `self` as a virtual DOM. Use the given `Bump` for temporary
54 fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
59impl<'r, R> Render for &'r R
63 fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
71impl<R> Render for Rc<R>
75 fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
83/// A `RootRender` is a render component that can be the root rendering component
84/// mounted to a virtual DOM.
86/// In addition to rendering, it must also be `'static` so that it can be owned
87/// by the virtual DOM and `Any` so that it can be downcast to its concrete type
88/// by event listener callbacks.
90/// You do not need to implement this trait by hand: there is a blanket
91/// implementation for all `Render` types that fulfill the `RootRender`
93pub trait RootRender: Any + Render {
94 /// Get this `&RootRender` trait object as an `&Any` trait object reference.
95 fn as_any(&self) -> &Any;
97 /// Get this `&mut RootRender` trait object as an `&mut Any` trait object
99 fn as_any_mut(&mut self) -> &mut Any;
102impl<T: Any + Render> RootRender for T {
103 fn as_any(&self) -> &Any {
107 fn as_any_mut(&mut self) -> &mut Any {
113 /// Downcast this shared `&dyn RootRender` trait object reference to its
114 /// underlying concrete type.
118 /// Panics if this virtual DOM's root rendering component is not an `R`
120 pub fn unwrap_ref<R: RootRender>(&self) -> &R {
123 .expect_throw("bad `RootRender::unwrap_ref` call")
126 /// Downcast this exclusive `&mut dyn RootRender` trait object reference to
127 /// its underlying concrete type.
131 /// Panics if this virtual DOM's root rendering component is not an `R`
133 pub fn unwrap_mut<R: RootRender>(&mut self) -> &mut R {
136 .expect_throw("bad `RootRender::unwrap_ref` call")
143 fn render_is_object_safe() {
145 fn takes_dyn_render(_: &dyn super::Render) {}
149 fn root_render_is_object_safe() {
151 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