Using lol-html directly in rust worker

Hi,

Has anyone seen a proof-of-concept of directly using lol-html in a rust worker? I’d like to implement someting a bit like the HTMLRewriter but want some custom functionality. I’ve played around and got quite close to having something which works, but my rust knowledge isn’t strong enough to understand some of the async compiler errors I am receiving. Having an example would hopefully give me a nice starting point.

Thanks!

2 Likes

Hi,

Would you be able to share the compiler errors you are receiving? I just tried compiling a Rust worker which uses lol-html and was able to get a wasm build without any error.

Hi,

Thanks for the response. I was mainly having issues outputting the html in a ‘streaming’ fashion. That is, I’d like write the chunks given in handle_chunk directly to the response stream (as opposed to building up a string and then converting that to a stream to attach to the response). Specifically, I was having problems because handle_chunk is not an async function, so I couldn’t call the async function to write to the stream within it.

I don’t suppose you have an example of the successful program you compiled that you could share?

Thanks!

I used the example from the lol-html readme: GitHub - cloudflare/lol-html: Low output latency streaming HTML parser/rewriter with CSS selector-based API (modified to return a String from the utf8 bytes in the output)

Can you share the compiler errors and/or the code snippet you’re working with? Happy to take a look. You might also want to open an issue on the GitHub repo directly, where some folks with more expertise with the crate can take a look.