on master help sign in
silence warnings about dyn Trait
ab96393ldesgoui
src/events.rs+2−2
@@ -86,7 +86,7 @@ cfg_if::cfg_if! {
86 callback(component, vdom_weak, event);
86 callback(component, vdom_weak, event);
87 }
87 }
88 }
88 }
89− }) as Box<Fn(web_sys::Event, u32, u32)>);
89+ }) as Box<dyn Fn(web_sys::Event, u32, u32)>);
90
90
91 (registry, closure)
91 (registry, closure)
92 }
92 }
@@ -99,7 +99,7 @@ cfg_if::cfg_if! {
99
99
100 pub(crate) fn remove_subtree(&mut self, node: &Node) {
100 pub(crate) fn remove_subtree(&mut self, node: &Node) {
101 match node.kind {
101 match node.kind {
102− NodeKind::Cached(_) | NodeKind::Text(_) => return,
102+ NodeKind::Cached(_) | NodeKind::Text(_) => {},
103 NodeKind::Element(&ElementNode {listeners, children, ..}) => {
103 NodeKind::Element(&ElementNode {listeners, children, ..}) => {
104 for l in listeners {
104 for l in listeners {
105 self.remove(l);
105 self.remove(l);
src/lib.rs+1−1
@@ -123,7 +123,7 @@ cfg_if::cfg_if! {
123 /// An element node in the physical DOM.
123 /// An element node in the physical DOM.
124 pub type Element = web_sys::Element;
124 pub type Element = web_sys::Element;
125
125
126− pub(crate) type EventsTrampoline = wasm_bindgen::closure::Closure<Fn(web_sys::Event, u32, u32)>;
126+ pub(crate) type EventsTrampoline = wasm_bindgen::closure::Closure<dyn Fn(web_sys::Event, u32, u32)>;
127 }
127 }
128}
128}
129
129
src/render.rs+4−4
@@ -71,22 +71,22 @@ where
71/// requirements.
71/// requirements.
72pub trait RootRender: Any + Render {
72pub trait RootRender: Any + Render {
73 /// Get this `&RootRender` trait object as an `&Any` trait object reference.
73 /// Get this `&RootRender` trait object as an `&Any` trait object reference.
74− fn as_any(&self) -> &Any;
74+ fn as_any(&self) -> &dyn Any;
75
75
76 /// Get this `&mut RootRender` trait object as an `&mut Any` trait object
76 /// Get this `&mut RootRender` trait object as an `&mut Any` trait object
77 /// reference.
77 /// reference.
78− fn as_any_mut(&mut self) -> &mut Any;
78+ fn as_any_mut(&mut self) -> &mut dyn Any;
79}
79}
80
80
81impl<T> RootRender for T
81impl<T> RootRender for T
82where
82where
83 T: Any + Render,
83 T: Any + Render,
84{
84{
85− fn as_any(&self) -> &Any {
85+ fn as_any(&self) -> &dyn Any {
86 self
86 self
87 }
87 }
88
88
89− fn as_any_mut(&mut self) -> &mut Any {
89+ fn as_any_mut(&mut self) -> &mut dyn Any {
90 self
90 self
91 }
91 }
92}
92}
src/vdom.rs+10−7
@@ -55,7 +55,7 @@ pub(crate) struct VdomInnerExclusive {
55 // Always `Some` except just before we drop. Just an option so that
55 // Always `Some` except just before we drop. Just an option so that
56 // `unmount` can take the component out but we can still have a Drop
56 // `unmount` can take the component out but we can still have a Drop
57 // implementation.
57 // implementation.
58− component: Option<Box<RootRender>>,
58+ component: Option<Box<dyn RootRender>>,
59
59
60 dom_buffers: Option<[Bump; 2]>,
60 dom_buffers: Option<[Bump; 2]>,
61 change_list: ManuallyDrop<ChangeListPersistentState>,
61 change_list: ManuallyDrop<ChangeListPersistentState>,
@@ -158,12 +158,15 @@ impl Vdom {
158 where
158 where
159 R: RootRender,
159 R: RootRender,
160 {
160 {
161− Self::with_boxed_root_render(container, Box::new(component) as Box<RootRender>)
161+ Self::with_boxed_root_render(container, Box::new(component) as Box<dyn RootRender>)
162 }
162 }
163
163
164 /// Construct a `Vdom` with the already-boxed-as-a-trait-object root
164 /// Construct a `Vdom` with the already-boxed-as-a-trait-object root
165 /// rendering component.
165 /// rendering component.
166− pub fn with_boxed_root_render(container: &crate::Element, component: Box<RootRender>) -> Vdom {
166+ pub fn with_boxed_root_render(
167+ container: &crate::Element,
168+ component: Box<dyn RootRender>,
169+ ) -> Vdom {
167 crate::strace::init_strace();
170 crate::strace::init_strace();
168
171
169 let dom_buffers = [Bump::new(), Bump::new()];
172 let dom_buffers = [Bump::new(), Bump::new()];
@@ -217,7 +220,7 @@ impl Vdom {
217 R: RootRender,
220 R: RootRender,
218 {
221 {
219 let mut exclusive = self.inner.exclusive.borrow_mut();
222 let mut exclusive = self.inner.exclusive.borrow_mut();
220− let component = Box::new(component) as Box<RootRender>;
223+ let component = Box::new(component) as Box<dyn RootRender>;
221 exclusive.component = Some(component);
224 exclusive.component = Some(component);
222 exclusive.render();
225 exclusive.render();
223 }
226 }
@@ -237,7 +240,7 @@ impl Vdom {
237 /// Unmount this virtual DOM, unregister its event listeners, and return its
240 /// Unmount this virtual DOM, unregister its event listeners, and return its
238 /// root render component.
241 /// root render component.
239 #[inline]
242 #[inline]
240− pub fn unmount(self) -> Box<RootRender> {
243+ pub fn unmount(self) -> Box<dyn RootRender> {
241 Rc::try_unwrap(self.inner.clone())
244 Rc::try_unwrap(self.inner.clone())
242 .map_err(|_| ())
245 .map_err(|_| ())
243 .unwrap_throw()
246 .unwrap_throw()
@@ -323,7 +326,7 @@ impl VdomInnerExclusive {
323 }
326 }
324}
327}
325
328
326−fn request_animation_frame(f: &Closure<FnMut()>) {
329+fn request_animation_frame(f: &Closure<dyn FnMut()>) {
327 web_sys::window()
330 web_sys::window()
328 .expect_throw("should have a window")
331 .expect_throw("should have a window")
329 .request_animation_frame(f.as_ref().unchecked_ref())
332 .request_animation_frame(f.as_ref().unchecked_ref())
@@ -340,7 +343,7 @@ where
340 let f = Closure::wrap(Box::new(move || {
343 let f = Closure::wrap(Box::new(move || {
341 *g.borrow_mut() = None;
344 *g.borrow_mut() = None;
342 f();
345 f();
343− }) as Box<FnMut()>);
346+ }) as Box<dyn FnMut()>);
344 request_animation_frame(&f);
347 request_animation_frame(&f);
345
348
346 *h.borrow_mut() = Some(f);
349 *h.borrow_mut() = Some(f);