&JsValue
-> &T
where T
is an exported Rust struct
#3943
-
Hi, is there a way to convert a The
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No, there isn't at the moment. A literal With a Also,
It probably should be public, but it's a bit of a mess: see #3709 for the history here. |
Beta Was this translation helpful? Give feedback.
No, there isn't at the moment.
A literal
&JsValue
->&T
transformation wouldn't work. The reason is that the way that borrowing Rust types works is thatwasm-bindgen
wraps them in an internalRefCell
which it borrows every time a reference is passed to an exported Rust function, and then at the end of the function theRef
/RefMut
is dropped to mark theRefCell
as non-borrowed again. Otherwise JavaScript could easily pass the sameT
in for two different&mut T
parameters of a function and cause undefined behaviour.With a
&T
, there's no way to run some code when it's dropped; so, such an API would require creating some kind ofRef<T>
orHandle<T>
type which you can then turn&JsValue
into.