I'm playing with wasm-bindgen ( https://github.com/rustwasm/wasm-bindgen ), just out of curiosity.
While playing with the Navigator (web_sys crate) I stumbled upon this method:
https://docs.rs/web-sys/0.3.36/web_sys/struct.MediaDevices.html#method.enumerate_devices
it returns a Result<Promise, JsValue>..now, I'm new to Rust, and my question is how can I fetch the value of the Promise?
How the Closure::wrap works?
How to use it with then method to fetch the results?
I wonder if someone could be so kind to explain me how to deal with Promise
Here an example that returns a Promise:
let window = web_sys::window().expect("no global `window` exists");
let navigator = window.navigator();
if let Ok(devs) = navigator.media_devices() {
if let Ok(prom) = devs.enumerate_devices() {
//..??? how to list all devices
}
}
All the best, Luca