|
pub trait TokenSink { |
|
type Handle; |
|
|
|
/// Process a token. |
|
fn process_token(&self, token: Token, line_number: u64) -> TokenSinkResult<Self::Handle>; |
|
|
|
// Signal sink that tokenization reached the end. |
|
fn end(&self) {} |
|
|
|
/// Used in the markup declaration open state. By default, this always |
|
/// returns false and thus all CDATA sections are tokenized as bogus |
|
/// comments. |
|
/// <https://html.spec.whatwg.org/multipage/#markup-declaration-open-state> |
|
fn adjusted_current_node_present_but_not_in_html_namespace(&self) -> bool { |
|
false |
|
} |
|
} |
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.
html5ever/html5ever/src/tokenizer/interface.rs
Lines 83 to 99 in 4641184
The
TokenSinktrait'sprocess_tokenmethod takes&selfMany usecases for a
TokenSinkare going to involve mutability. This includes multiple files in this repo such as tree_builder.I think
TokenSinkwould be better like this:Usecases that need mutability could then be
impl TokenSink for &mut MyTokenSink, and those that don't like the printer examples can beimpl TokenSink for &MyType.I haven't tried implementing this refactor, it might not actually work out well.