Skip to content

Thoughts on an html! macro that emits an impl Read value #37

@infogulch

Description

@infogulch

Hi! First I want to say thank you for making this library! I appreciate the features and principles you aimed for, especially "non opinionated" parser that accepts any xml-like pattern, the minimal dependencies (especially avoiding wasm-bindgen), and a modular design that exposes the parsed node tree as a base to build any kind of macro on top of.

Because of these features I was able to easily integrate html-to-string-macro into a demo project based around htmx, a library that adds interactivity to html by requesting html fragments over http and inserting them into the DOM (an approach that offers more bang-for-buck than its simplistic appearance indicates). (See also htmx intro presentation if you like.)


I'd like to expand this demo project to be something more, but I'm concerned that that deeply recursive use of html-to-string-macro's html! would lead to O(n²) performance due to repeatedly calling format! on larger and larger fragments of the page as the page is gradually built up.

To solve this I'm thinking about writing a new implementation of the html! macro, maybe called html-to-reader-macro, that instead of emitting a String it emits a value that implements the Read trait. The idea being that you can build up a big graph of objects that impl Read and then calling read() on the root will traverse through the component tree and scan out all the bytes directly into the final destination buffer exactly once with no unnecessary intermediate copying.

What do you think? Useful? Feasible? Gotchas?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions