cloudflare / cloudflare/lol-html
Make `Element.on_end_tag` handler `'h` instead of `'static`
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 111
- PR merge metrics
- No merged PRs in 30d
Description
While right now the main handlers can borrow data from the surrounding scope `on_end_tag` can't. This means that the data needs to be copped, put into an Rc or similar. Since IIUC this handler is not stored past the lifetime of the rewriter it would be nice if the lifetime reflected that.
Alternatively add an `element_end` handler to `ElementContentHandlers` as those handlers have the expected lifetime, this would also reduce allocations as the handler only needs to be allocated once instead of for each element.
I think the ideal state would be to replace `ElementContentHandlers` with a trait that could be implemented as it is basically a strange trait right now (you just need to "define" methods at runtime rather than implementing a trait). It would probably be possible to swap it out for a trait while maintaining the current API for most uses. But that is a bigger change and would probably need a new API to avoid breaking existing users (but the old API could just map to the new one).
Contributor guide
Research direction
No file or test is named. Start by tracing the definitions and uses of Element.on_end_tag and ElementContentHandlers, then compare their handler lifetimes and allocation behavior. Done would require an agreed API design that permits the intended borrowing or provides the proposed element_end handler without breaking existing users.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- web-dev
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100