[examples] closures - port to rust 2018

This commit is contained in:
LachezarLechev 2018-12-11 08:39:49 +01:00
parent 26737a2888
commit 7107a896da
2 changed files with 4 additions and 5 deletions

View File

@ -2,6 +2,7 @@
name = "closures"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
[lib]
crate-type = ["cdylib"]

View File

@ -1,6 +1,4 @@
extern crate js_sys;
extern crate wasm_bindgen;
extern crate web_sys;
use web_sys;
use js_sys::{Array, Date};
use wasm_bindgen::prelude::*;
@ -67,7 +65,7 @@ fn setup_clock(window: &Window, document: &Document) -> Result<(), JsValue> {
.get_element_by_id("current-time")
.expect("should have #current-time on the page");
update_time(&current_time);
let a = Closure::wrap(Box::new(move || update_time(&current_time)) as Box<Fn()>);
let a = Closure::wrap(Box::new(move || update_time(&current_time)) as Box<dyn Fn()>);
window
.set_interval_with_callback_and_timeout_and_arguments_0(a.as_ref().unchecked_ref(), 1000)?;
fn update_time(current_time: &Element) {
@ -103,7 +101,7 @@ fn setup_clicker(document: &Document) {
let a = Closure::wrap(Box::new(move || {
clicks += 1;
num_clicks.set_inner_html(&clicks.to_string());
}) as Box<FnMut()>);
}) as Box<dyn FnMut()>);
document
.get_element_by_id("green-square")
.expect("should have #green-square on the page")