Replies: 3 comments
-
I hacked around this using the following macro which I modified from the macro_rules! object {
($($key:expr => $value:expr,)+) => { object!($($key => $value),+) };
($($key:expr => $value:expr),*) => {
{
let mut _obj = ::js_sys::Object::new();
$(
js_sys::Reflect::set(&_obj, &($key.into()), &($value.into())).unwrap();
)*
_obj
}
};
} If there is no better way to do this kind of thing, then this might be useful to build into the crate. |
Beta Was this translation helpful? Give feedback.
-
Bump, I would very much like an answer to the same 👍 |
Beta Was this translation helpful? Give feedback.
-
You might want to take a look at Alternatively, the most straightforward way would be to use |
Beta Was this translation helpful? Give feedback.
-
Summary
Is there a canonical way to serialize a struct which contains another
JsValue
?Additional Details
I am trying to implement bindings for https://cesium.com/learn/cesiumjs/ref-doc/Viewer.html, and am running into issues creating bindings for the
ConstructorOptions
object. This object you need to be able to provide anImageryProvider
, which itself is a javascript object which needs to be generated by a constructor. However, sinceJsValue
does not implementSerialize
you can't#[derive(Serialize)]
for a struct which contains anImageryProvider
. My question is what is the canonical way to handle transporting such data from Rust to Javascript?Beta Was this translation helpful? Give feedback.
All reactions