TokenSink trait forces interior mutability/RefCell usage
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 288
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 8
Description
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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