Function js_unbox

Source
pub unsafe fn js_unbox<T>(v: Value) -> Option<T>
Expand description

Unboxes a value created by js_box, returning the original object.

Returns Some(v) if the unboxing succeeded, or None if the value was not a valid box object or it was already unboxed.

This mutates the object, so that calling js_unbox on the same object will return None.

§Safety

Assumes that the object has been untouched since being returned from js_box or js_box_from_std_box, and that the type argument is the same as the one used to box it.

JS or Rust code could modify the object or construct a JS object with an invalid internal pointer, which this function can’t check for. In such a case, the result is undefined.

If the value is sent across a thread, the caller needs to ensure that T implements Send (TODO: is this even possible with wasm?).

The lifetime of T must still be valid. If in doubt, require 'static.