mitsuhiko / similar

A high level diffing library for rust based on diffs
https://insta.rs/similar
Apache License 2.0
949 stars 31 forks source link

Compiling to WASM #46

Open saona-raimundo opened 1 year ago

saona-raimundo commented 1 year ago

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 commented 1 year ago

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

saona-raimundo commented 1 year ago

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 commented 1 year ago

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.