Hello Rustaceans,
I'm a new Rustacean and I'm into Rust + WASM.
How could this creation of a js_sys::Function from a wasm_bindgen::closure::Closure be less verbose?
E.g.
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen::JsCast;
use wasm_bindgen::prelude::*;
use web_sys::{Window, window};
#[wasm_bindgen]
pub fn run() {
let wind = Rc::new(window().unwrap() as Window);
let wind1 = wind.clone();
let mut update = Rc::new(RefCell::new(None));
let update1 = update.clone();
*update.borrow_mut() = Some(Closure::wrap(Box::new(move || {
wind1.alert_with_message("Beep!");
wind1.request_animation_frame((update1.borrow().as_ref().unwrap() as &Closure<dyn Fn()>).as_ref().unchecked_ref());
}) as Box<dyn Fn()>));
wind.request_animation_frame((update.borrow().as_ref().unwrap() as &Closure<dyn Fn()>).as_ref().unchecked_ref());
}
corresponds to
function update() {
alert("Beep!");
window.requestAnimationFrame(update);
}
window.requestAnimationFrame(update);
I can't read/understand it without basically writing it again and it was tedious to do so!
How could this be expressed more concisely or abstracted away from it?
It is greeting you,
kevinvenisonowlpeach