cloudflare / cloudflare/lol-html
Add blanket `impl<T: Write> OutputSink for T`
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 111
- PR merge metrics
- No merged PRs in 30d
Description
Currently, `HtmlRewriter::try_new` takes _only_ closures and nothing else. For the common case of 'I have a buffer to write to' this causes the code to be more complicated than necessary:
```rust
let mut output = vec![];
// NOTE: never panics because encoding is always "utf-8".
let mut rewriter = HtmlRewriter::try_new(settings.into(), |c: &[u8]| {
output.extend_from_slice(c);
})
.unwrap();
```
If `OutputSink` took any `io::Write` impl, it could be simpler:
```rust
let mut output = vec![];
// NOTE: never panics because encoding is always "utf-8".
let mut rewriter = HtmlRewriter::try_new(settings.into(), &mut output).unwrap();
```
Contributor guide
Research direction
Start at OutputSink and HtmlRewriter::try_new, then trace how the current closure sink is accepted. Check the existing output-handling examples or tests; done means a mutable io::Write target can be passed directly while the current closure-based usage remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100