on master help sign in
silence warnings about dyn Trait
commitab96393a26a7e1423f16376d685617cc3baf8151 authorldesgoui <ldesgoui@ldesgoui.xyz> dateSat 30 Nov 2019, 03:45 (7 years ago) parent957fec4
4 files changed+17−14
src/events.rs+2−2 src/lib.rs+1−1 src/render.rs+4−4 src/vdom.rs+10−7
src/events.rs+2−2
@@ -86,7 +86,7 @@ cfg_if::cfg_if! {
8686 callback(component, vdom_weak, event);
8787 }
8888 }
89− }) as Box<Fn(web_sys::Event, u32, u32)>);
89+ }) as Box<dyn Fn(web_sys::Event, u32, u32)>);
9090
9191 (registry, closure)
9292 }
@@ -99,7 +99,7 @@ cfg_if::cfg_if! {
9999
100100 pub(crate) fn remove_subtree(&mut self, node: &Node) {
101101 match node.kind {
102− NodeKind::Cached(_) | NodeKind::Text(_) => return,
102+ NodeKind::Cached(_) | NodeKind::Text(_) => {},
103103 NodeKind::Element(&ElementNode {listeners, children, ..}) => {
104104 for l in listeners {
105105 self.remove(l);
src/lib.rs+1−1
@@ -123,7 +123,7 @@ cfg_if::cfg_if! {
123123 /// An element node in the physical DOM.
124124 pub type Element = web_sys::Element;
125125
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)>;
127127 }
128128}
129129
src/render.rs+4−4
@@ -71,22 +71,22 @@ where
7171/// requirements.
7272pub trait RootRender: Any + Render {
7373 /// Get this `&RootRender` trait object as an `&Any` trait object reference.
74− fn as_any(&self) -> &Any;
74+ fn as_any(&self) -> &dyn Any;
7575
7676 /// Get this `&mut RootRender` trait object as an `&mut Any` trait object
7777 /// reference.
78− fn as_any_mut(&mut self) -> &mut Any;
78+ fn as_any_mut(&mut self) -> &mut dyn Any;
7979}
8080
8181impl<T> RootRender for T
8282where
8383 T: Any + Render,
8484{
85− fn as_any(&self) -> &Any {
85+ fn as_any(&self) -> &dyn Any {
8686 self
8787 }
8888
89− fn as_any_mut(&mut self) -> &mut Any {
89+ fn as_any_mut(&mut self) -> &mut dyn Any {
9090 self
9191 }
9292}
src/vdom.rs+10−7
@@ -55,7 +55,7 @@ pub(crate) struct VdomInnerExclusive {
5555 // Always `Some` except just before we drop. Just an option so that
5656 // `unmount` can take the component out but we can still have a Drop
5757 // implementation.
58− component: Option<Box<RootRender>>,
58+ component: Option<Box<dyn RootRender>>,
5959
6060 dom_buffers: Option<[Bump; 2]>,
6161 change_list: ManuallyDrop<ChangeListPersistentState>,
@@ -158,12 +158,15 @@ impl Vdom {
158158 where
159159 R: RootRender,
160160 {
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>)
162162 }
163163
164164 /// Construct a `Vdom` with the already-boxed-as-a-trait-object root
165165 /// 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 {
167170 crate::strace::init_strace();
168171
169172 let dom_buffers = [Bump::new(), Bump::new()];
@@ -217,7 +220,7 @@ impl Vdom {
217220 R: RootRender,
218221 {
219222 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>;
221224 exclusive.component = Some(component);
222225 exclusive.render();
223226 }
@@ -237,7 +240,7 @@ impl Vdom {
237240 /// Unmount this virtual DOM, unregister its event listeners, and return its
238241 /// root render component.
239242 #[inline]
240− pub fn unmount(self) -> Box<RootRender> {
243+ pub fn unmount(self) -> Box<dyn RootRender> {
241244 Rc::try_unwrap(self.inner.clone())
242245 .map_err(|_| ())
243246 .unwrap_throw()
@@ -323,7 +326,7 @@ impl VdomInnerExclusive {
323326 }
324327}
325328
326−fn request_animation_frame(f: &Closure<FnMut()>) {
329+fn request_animation_frame(f: &Closure<dyn FnMut()>) {
327330 web_sys::window()
328331 .expect_throw("should have a window")
329332 .request_animation_frame(f.as_ref().unchecked_ref())
@@ -340,7 +343,7 @@ where
340343 let f = Closure::wrap(Box::new(move || {
341344 *g.borrow_mut() = None;
342345 f();
343− }) as Box<FnMut()>);
346+ }) as Box<dyn FnMut()>);
344347 request_animation_frame(&f);
345348
346349 *h.borrow_mut() = Some(f);