web_sys::js_sys::Function
's different behaviors
#3895
Replies: 1 comment 1 reply
-
Serde is mostly designed for serialising/deserialising data from formats like JSON, YAML, and TOML, and in those contexts deserialising to a JavaScript function makes no sense. However, if you're using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have been working with
web_sys::js_sys::Function
in 2 different scenarios; first one is inside a struct as follows:The second one is as a parameter in a function; like this:
I can use the later without any problems, which is, I can call it from my JS code and pass a JS function as an argument to it and let
some_function
call that argument. But in the former, I've been facing a issue related to theweb_sys::js_sys::Function
type not implementing theDeserialize<'_>
trait.My question is, what exactly is the technical issue with (de)serializing functions?(
web_sys::js_sys::Function
, to be more precise). Why can't we employ the same behavior(as in later scenario, which is passing only a reference to the JS function I presume) for structs in case of functions as well? Is There a workaround to use this type in such structs anyways?Beta Was this translation helpful? Give feedback.
All reactions