@@ -58,11 +58,6 @@
5858// Re-export the `bumpalo` crate.
5959pub use bumpalo;
6060
61−use bumpalo::Bump;
62−use std::any::Any;
63−use std::rc::Rc;
64−use wasm_bindgen::UnwrapThrowExt;
65−
6661// Only `pub` so that the wasm-bindgen bindings work.
6762#[doc(hidden)]
6863pub mod change_list;
@@ -70,111 +65,11 @@ pub mod change_list;
7065mod cached;
7166mod events;
7267mod node;
68+mod render;
7369mod vdom;
7470
7571// Re-export items at the top level.
7672pub use self::cached::Cached;
7773pub use self::node::{on, Attribute, ElementNode, Listener, ListenerCallback, Node, TextNode};
74+pub use self::render::{Render, RootRender};
7875pub use self::vdom::{Vdom, VdomWeak};
79−
80−pub trait Render {
81− fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
82− where
83− 'a: 'bump;
84−}
85−
86−impl<'r, R> Render for &'r R
87−where
88− R: Render,
89−{
90− fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
91− where
92− 'a: 'bump,
93− {
94− (**self).render(bump)
95− }
96−}
97−
98−impl<R> Render for Rc<R>
99−where
100− R: Render,
101−{
102− fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
103− where
104− 'a: 'bump,
105− {
106− (**self).render(bump)
107− }
108−}
109−
110−/// A `RootRender` is a render component that can be the root rendering component
111−/// mounted to a virtual DOM.
112−///
113−/// In addition to rendering, it must also be `'static` so that it can be owned
114−/// by the virtual DOM and `Any` so that it can be downcast to its concrete type
115−/// by event listener callbacks.
116−///
117−/// You do not need to implement this trait by hand: there is a blanket
118−/// implementation for all `Render` types that fulfill the `RootRender`
119−/// requirements.
120−pub trait RootRender: Any + Render {
121− /// Get this `&RootRender` trait object as an `&Any` trait object reference.
122− fn as_any(&self) -> &Any;
123−
124− /// Get this `&mut RootRender` trait object as an `&mut Any` trait object
125− /// reference.
126− fn as_any_mut(&mut self) -> &mut Any;
127−}
128−
129−impl<T: Any + Render> RootRender for T {
130− fn as_any(&self) -> &Any {
131− self
132− }
133−
134− fn as_any_mut(&mut self) -> &mut Any {
135− self
136− }
137−}
138−
139−impl dyn RootRender {
140− /// Downcast this shared `&dyn RootRender` trait object reference to its
141− /// underlying concrete type.
142− ///
143− /// # Panics
144− ///
145− /// Panics if this virtual DOM's root rendering component is not an `R`
146− /// instance.
147− pub fn unwrap_ref<R: RootRender>(&self) -> &R {
148− self.as_any()
149− .downcast_ref::<R>()
150− .expect_throw("bad `RootRender::unwrap_ref` call")
151− }
152−
153− /// Downcast this exclusive `&mut dyn RootRender` trait object reference to
154− /// its underlying concrete type.
155− ///
156− /// # Panics
157− ///
158− /// Panics if this virtual DOM's root rendering component is not an `R`
159− /// instance.
160− pub fn unwrap_mut<R: RootRender>(&mut self) -> &mut R {
161− self.as_any_mut()
162− .downcast_mut::<R>()
163− .expect_throw("bad `RootRender::unwrap_ref` call")
164− }
165−}
166−
167−#[cfg(test)]
168−mod tests {
169− #[test]
170− fn render_is_object_safe() {
171− #[allow(dead_code)]
172− fn takes_dyn_render(_: &dyn super::Render) {}
173− }
174−
175− #[test]
176− fn root_render_is_object_safe() {
177− #[allow(dead_code)]
178− fn takes_dyn_render(_: &dyn super::RootRender) {}
179− }
180−}