Skip to content

WASM version of the parser #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dubadub opened this issue Mar 12, 2025 · 7 comments
Open

WASM version of the parser #31

dubadub opened this issue Mar 12, 2025 · 7 comments
Labels
help wanted Extra attention is needed

Comments

@dubadub
Copy link
Member

dubadub commented Mar 12, 2025

Idea in one sentence

Allows developers to use Rust parser in JS world.

@dubadub
Copy link
Member Author

dubadub commented Mar 24, 2025

Current draft PR #27

@dubadub dubadub moved this to Backlog in Cooklang Project Mar 24, 2025
@dubadub dubadub transferred this issue from cooklang/.github Mar 25, 2025
@dubadub dubadub added the help wanted Extra attention is needed label Mar 25, 2025
@dubadub
Copy link
Member Author

dubadub commented Mar 28, 2025

WebAssembly (Wasm) allows us to compile Rust parser code into a .wasm binary, which can be loaded into TypeScript using tools like wasm-bindgen and WebAssembly.instantiate, enabling TS to call Rust functions as if they were regular JavaScript functions.

I experimented a bit and have a draft PR. It can parse a recipe from TS with the help of serde-wasm-bindgen crate but because the return is just a big JS object it's not handy working with it for developers. So as next step I wanted to create wrapper objects for better dev experience and TS definitions.

I tried to do that on rust side with wasm_bindgen declarations, but it turned out bulky. Maybe we can simply define objects on TS side and rewrap response. I can give more examples if needed.

@dfego
Copy link
Member

dfego commented Mar 28, 2025

What would an appropriate end user experience be on the TS side? Under the hood, the Rust parser has all that data, but it's got convenience methods and stuff, right?

I tried to do that on rust side with wasm_bindgen declarations, but it turned out bulky. Maybe we can simply define objects on TS side and rewrap response. I can give more examples if needed.

Is the result of this the link you posted, or is it something else? Trying to see what you mean by trying to use wasm_bindgen declarations being bulky.

@dubadub
Copy link
Member Author

dubadub commented Mar 28, 2025

That was my first iteration f08b9b0 with wasm_bindgen. Tbh I forgot why I decided to use serde approach, maybe respective TS classes not generated, or something. I decided to try doing minimum on rust side and handle everything in TS.

@dubadub
Copy link
Member Author

dubadub commented Mar 28, 2025

It could be just enough repeating existing (before Rust) interface to make it usable.

@dfego
Copy link
Member

dfego commented Mar 28, 2025

I don't know much about wasm_bindgen yet, but what would stop one from putting those derive macros directly in the canonical parser objects? Like, directly on Recipe and Ingredients and stuff?

@dubadub
Copy link
Member Author

dubadub commented Mar 28, 2025

Actually, it might work, I'm not sure about specific requirements it has.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
Status: Backlog
Development

No branches or pull requests

2 participants