From 991e61931ec54cbc8b870761491bf181041a7ad3 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 3 Oct 2018 09:53:55 -0700 Subject: [PATCH] Switch `Closure::new` to `wrap` in paint example Show off stable usage! --- examples/paint/Cargo.toml | 2 +- examples/paint/src/lib.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/paint/Cargo.toml b/examples/paint/Cargo.toml index 7ca8c5e59..9b0fcc24e 100644 --- a/examples/paint/Cargo.toml +++ b/examples/paint/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib"] [dependencies] js-sys = { path = "../../crates/js-sys" } -wasm-bindgen = { path = "../..", features = ["nightly"] } +wasm-bindgen = { path = "../.." } [dependencies.web-sys] path = "../../crates/web-sys" diff --git a/examples/paint/src/lib.rs b/examples/paint/src/lib.rs index f7abc5202..b842bac8c 100644 --- a/examples/paint/src/lib.rs +++ b/examples/paint/src/lib.rs @@ -36,11 +36,11 @@ pub fn main() { { let context = context.clone(); let pressed = pressed.clone(); - let closure: Closure = Closure::new(move |event: web_sys::MouseEvent| { + let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| { context.begin_path(); context.move_to(event.offset_x() as f64, event.offset_y() as f64); pressed.set(true); - }); + }) as Box); (canvas.as_ref() as &web_sys::EventTarget) .add_event_listener_with_callback("mousedown", closure.as_ref().unchecked_ref()) .unwrap(); @@ -49,14 +49,14 @@ pub fn main() { { let context = context.clone(); let pressed = pressed.clone(); - let closure: Closure = Closure::new(move |event: web_sys::MouseEvent| { + let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| { if pressed.get() { context.line_to(event.offset_x() as f64, event.offset_y() as f64); context.stroke(); context.begin_path(); context.move_to(event.offset_x() as f64, event.offset_y() as f64); } - }); + }) as Box); (canvas.as_ref() as &web_sys::EventTarget) .add_event_listener_with_callback("mousemove", closure.as_ref().unchecked_ref()) .unwrap(); @@ -65,11 +65,11 @@ pub fn main() { { let context = context.clone(); let pressed = pressed.clone(); - let closure: Closure = Closure::new(move |event: web_sys::MouseEvent| { + let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| { pressed.set(false); context.line_to(event.offset_x() as f64, event.offset_y() as f64); context.stroke(); - }); + }) as Box); (canvas.as_ref() as &web_sys::EventTarget) .add_event_listener_with_callback("mouseup", closure.as_ref().unchecked_ref()) .unwrap();