Getting Object from JsValue(MIDIAccess)

I have variable x = JsValue(MIDIAccess). How do I get to the MIDIAccess object? I tried x.0 but get an error stating the field is undefined.

Thanks,

From the names of your types, I presume you're using web_sys and wasm_bindgen.

JsValue isn't a tuple, so .0 will not work. The JsCast trait can be used to cast between JS types:

use wasm_bindgen::JsCast;

let midi: Result<MIDIAccess, JsValue> = x.dyn_into();

You can also use the standard From and Into traits, but I think they'll panic if you mix up your types.

Thank you, I got it working!