aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-30 17:35:23 +0100
committerMartin Fischer <martin@push-f.com>2021-12-05 02:52:36 +0100
commita22adb602c6eaed59256c8af0ae8d718a11ad5e3 (patch)
tree0c579c17150ce7bd1ab5e4cfbd1ab064a1a2eee8 /src
parent2cf4080bc7bc65092efdf64962862fa29c77c02c (diff)
spans: introduce GetPos trait
Diffstat (limited to 'src')
-rw-r--r--src/spans.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/spans.rs b/src/spans.rs
index cf65053..663bd59 100644
--- a/src/spans.rs
+++ b/src/spans.rs
@@ -8,6 +8,10 @@ use crate::{Doctype, Emitter, EndTag, Error, StartTag, Token};
type Span = std::ops::Range<usize>;
+pub trait GetPos {
+ fn get_pos(&self) -> usize;
+}
+
/// The default implementation of [`crate::Emitter`], used to produce ("emit") tokens.
pub struct SpanEmitter<R> {
current_characters: String,
@@ -33,7 +37,7 @@ impl<R> Default for SpanEmitter<R> {
}
}
-impl<R> SpanEmitter<R> {
+impl<R: GetPos> SpanEmitter<R> {
fn emit_token(&mut self, token: Token<Span>) {
self.flush_current_characters();
self.emitted_tokens.push_front(token);
@@ -77,7 +81,7 @@ impl<R> SpanEmitter<R> {
}
}
-impl<R> Emitter<R> for SpanEmitter<R> {
+impl<R: GetPos> Emitter<R> for SpanEmitter<R> {
type Token = Token<Span>;
fn set_last_start_tag(&mut self, last_start_tag: Option<&str>) {