rustyscript icon indicating copy to clipboard operation
rustyscript copied to clipboard

Marshalling of Rust functions/types like with `#[wasm-bindgen]` attributes?

Open Boscop opened this issue 1 year ago • 6 comments

Thanks for making this crate, it seems very useful 🙂

It it possible to do marshalling of Rust functions/types like with #[wasm-bindgen] attributes?

Or anything that's not as verbose as manual deserialization of the function arguments on the Rust side? :)

Thanks 🙏

Boscop avatar Oct 02 '24 11:10 Boscop

Can you show me an example of what you mean?

rscarson avatar Oct 02 '24 12:10 rscarson

I mean like this:

On Rust items: https://rustwasm.github.io/wasm-bindgen/reference/attributes/on-rust-exports/constructor.html

On JS items: https://rustwasm.github.io/wasm-bindgen/reference/attributes/on-js-imports/constructor.html

This would make interop much easier :)


Btw, I have another question: Is this crate the least-opinionated-possible layer on top of deno to make it useable inside a Rust host? In other words, would it make sense for me to use deno directly or always this crate, if my goal is to have an embedded JS runtime to extend the capabilities of my Rust host via JS scripting?

Boscop avatar Oct 02 '24 12:10 Boscop

I mean like this:

On Rust items: https://rustwasm.github.io/wasm-bindgen/reference/attributes/on-rust-exports/constructor.html

On JS items: https://rustwasm.github.io/wasm-bindgen/reference/attributes/on-js-imports/constructor.html

This would make interop much easier :)


Btw, I have another question: Is this crate the least-opinionated-possible layer on top of deno to make it useable inside a Rust host? In other words, would it make sense for me to use deno directly or always this crate, if my goal is to have an embedded JS runtime to extend the capabilities of my Rust host via JS scripting?

That was the goal of the project, yes

An unopinionated layer on top of deno existing only to simplify integration tasks with minimal overhead

rscarson avatar Oct 02 '24 13:10 rscarson

That was the goal of the project, yes An unopinionated layer on top of deno existing only to simplify integration tasks with minimal overhead

Ok great, just what I had hoped this would be :)

Sorry, I didn't want to derail the topic of this issue.. But yeah, considering this crate could be considered the "canonical" way to use Deno in a Rust host, it definitely would be super nice & ergonomic to have #[wasm-bindgen]-like attributes for marshalling 🙂

Boscop avatar Oct 02 '24 17:10 Boscop

Looking to implement this soon

Can I get more examples of how you picture this being used?

rscarson avatar Nov 04 '24 17:11 rscarson

Sorry for the late reply.. This page describes exactly what I meant:

On Rust items: https://rustwasm.github.io/wasm-bindgen/reference/attributes/on-rust-exports/constructor.html

On JS items: https://rustwasm.github.io/wasm-bindgen/reference/attributes/on-js-imports/constructor.html

It doesn't have to be #[wasm-bindgen] attributes if that's not possible, but a similar proc-macro attribute would be nice. This would make marshalling as ergonomic as it could be.

Boscop avatar Jan 10 '25 20:01 Boscop