mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 06:02:13 +00:00
[examples] closures - port to rust 2018
This commit is contained in:
parent
26737a2888
commit
7107a896da
@ -2,6 +2,7 @@
|
||||
name = "closures"
|
||||
version = "0.1.0"
|
||||
authors = ["The wasm-bindgen Developers"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
@ -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(¤t_time);
|
||||
let a = Closure::wrap(Box::new(move || update_time(¤t_time)) as Box<Fn()>);
|
||||
let a = Closure::wrap(Box::new(move || update_time(¤t_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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user