Skip to content
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

Compiling to WASM #46

Open
saona-raimundo opened this issue Apr 10, 2023 · 5 comments
Open

Compiling to WASM #46

saona-raimundo opened this issue Apr 10, 2023 · 5 comments

Comments

@saona-raimundo
Copy link

Hi! Thanks for the crate!

Goal

I was trying to do a web demo of similar. In particular, of the terminal-inline example.

Problem

The problem I faced is the use of the std::time module, which does not compile to Wasm.

Solutions

One solution is to hide the related functionalities behind a feature.

The one I would prefer is to simply change for an implementation of std::time that works on Wasm, like the instant crate.
It has both Instance and Duration, which all similar uses.

References

@mitsuhiko
Copy link
Owner

One option would be to just cfg out the uses of time. Would accept a patch for this.

@saona-raimundo
Copy link
Author

I gave it a try, putting all uses of std::time behind a feature...

But the use of deadline: Option<Instant> is extensively used because

  1. the public API that does not use it fallbacks to use the functions that use deadline with deadline None. So the actual implementation uses deadlines through the code.
  2. the private functions, for example, algorithms\myers\conquer uses deadlines in the logic.

Taking the code as it is and trying to include the feature superficially actually ends up duplicating quite some code.

Would you reconsider the instant crate?

@mustafa0x
Copy link

This project seems to compile it as WASM: https://github.com/xfbs/diff.rs

Related: I also would love to see a simple online text diffing tool similar to https://neil.fraser.name/software/diff_match_patch/demos/diff.html.

@saona-raimundo
Copy link
Author

Reporting back with the first draft of the playground.
This is bare bones, and only "Lines" mode work so far (I have not figured out why characters and words do not work yet).
There is no inline option because the inline implementation requires time.

https://saona-raimundo.github.io/similar_playground/

@druide
Copy link

druide commented Jan 18, 2025

I was successfully run "insta" tests in the Chrome with this update #71.
P.S. This crate uses "insta" for tests, but to run tests in a browser "insta" need this crate update, recursion :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants