servo / servo/html5ever

TokenSink trait forces interior mutability/RefCell usage

Open
#642 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.6k
Forks
288
Avg merge
2d 22h
Merged PRs (30d)
8

Description

https://github.com/servo/html5ever/blob/464118468457fde7ade8b511cdfa5588f8a10f41/html5ever/src/tokenizer/interface.rs#L83-L99

The TokenSink trait's process_token method takes &self

Many usecases for a TokenSink are going to involve mutability. This includes multiple files in this repo such as tree_builder.

I think TokenSink would be better like this:

pub trait TokenSink {
    type Handle;
    fn process_token(self, token: Token, line_number: u64) -> TokenSinkResult<Self::Handle>;
    fn end(self);
    fn adjusted_current_node_present_but_not_in_html_namespace(self);
}

Usecases that need mutability could then be impl TokenSink for &mut MyTokenSink, and those that don't like the printer examples can be impl TokenSink for &MyType.
I haven't tried implementing this refactor, it might not actually work out well.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with html5ever/src/tokenizer/interface.rs#L83-L99 and compare the TokenSink signature with the tree_builder implementation at the linked location. Check the printer examples and other TokenSink implementations to assess whether taking self or reference receivers works across the repository. Done means the refactor's feasibility and all affected implementations are resolved.

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
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.