I'm trying to implement a blocking work pool based on web workers for Rust when targeting WASM. So far I've got the following API for spawning tasks:
async fn spawn<D, R>(function: fn(D) -> R, data: D) -> R where D: Send + Clone + 'static, R: Send + Clone + 'static;
I've gotten it working conceptually, except for a big 'ol facepalm I hit just now when I realized that if
D is a
String it is actually a pointer type, and even though I am copying the bytes of the pointer when sending it to the web worker I'm not copying the data that the pointer points to!
I already feel that the answer is "no", but is there any way to somehow copy the pointer data and the data it points to for reasonably any sort of type? There can't be can there?
Now this is seeming like a bad idea. The whole time I was testing this I was testing it with
Copy types on the stack and thinking, "ah, it's working".