I wrote a little tool that helps you split a larger body of text into tweet (or other) sized pieces.
Input some text, and drag the slider to the maximum length each piece should be. The program will try to fill each piece as much as possible while only splitting on whitespace. That is, it should hopefully never split in the middle of anything that isn't a space or a line break.
I think it's neat, and not just for what it does, but how it was made.
First, I wrote a Rust library to split text on whitespace.
This is a standard Rust library with a
lib.rs file that exposes some functionality and a
that defines a simple CLI interface that looks like this:
$ tweet_split -h ts 0.1.0 USAGE: tweet_split [OPTIONS] [string] FLAGS: -h, --help Prints help information -V, --version Prints version information OPTIONS: -i, --input-path <input-path> Location of text to tweetify -l, --max-tweet-length <max-tweet-length> The maximum length of a tweet, in characters ARGS: <string>
Then I used the Rust web framework Yew to make a simple web app that compiles the previously mentioned whitespace-splitting library to WASM and exposes it on the web with some simple form and slider controls.
I didn't have to modify the splitting library at all in order for it to work on the web. I just included it in the web application, and used the Yew framework to handle the event-input and DOM rendering functionality. Overall this was incredibly pleasant. The compiler was a helpful tool along the way, and I knew that when things compiled my program would either handle inputs correctly or crash, rather than allow bad data.
I think this kind of work is going to be big in the near future: porting existing, useful Rust code to web interfaces to expose it to new, non-technical audiences.
The notion that WASM is useful only for high-performance contexts like graphics or scientific computing is incorrect. I see a few reasons why WASM will reach way beyond the high-performance domains.
First, being able to use existing code in new contexts with minimal changes is the holy grail for many companies, and in the coming years we will start to see many companies and groups port their existing Rust (or C, C++, etc) code to WASM contexts with surprisingly little adaptation for huge wins. Rust is the clear leader in treating WASM as first class, and we will see much more WASM as Rust starts to make its way along the adoption curve into larger and more prolific shops.
Finally, all of this attention will contribute to WASM becoming much more stable and well supported by browsers, so the ecosystem of tools for profiling it and debugging it will mature, the sizes of produced binary will come down, and development will get easier as frameworks like Yew start to mature.