aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-09-04 08:28:11 +0200
committerMartin Fischer <martin@push-f.com>2023-09-28 07:26:44 +0200
commit1e746e68f647eb42586ffab81fefa9f68723ed97 (patch)
tree12f5f004a4726729fa6ca85bfddc99c49d51929a
parent9dd2ac1c95c949066e341837650c3211769342c3 (diff)
feat: add blanket impl of Reader for boxed readers
-rw-r--r--CHANGELOG.md4
-rw-r--r--src/reader.rs16
2 files changed, 20 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e2613cd..03652cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
### [unreleased]
+#### Features
+
+* Added a blanket implementation to implement `Reader` for boxed readers.
+
#### Breaking changes
* `Emitter` trait
diff --git a/src/reader.rs b/src/reader.rs
index 3c39b16..7038847 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -55,6 +55,22 @@ impl<'a, R: 'a + Reader> IntoReader<'a> for R {
}
}
+impl<R: Reader + ?Sized> Reader for Box<R> {
+ type Error = R::Error;
+
+ fn read_char(&mut self) -> Result<Option<char>, Self::Error> {
+ self.as_mut().read_char()
+ }
+
+ fn try_read_string(&mut self, s: &str, case_sensitive: bool) -> Result<bool, Self::Error> {
+ self.as_mut().try_read_string(s, case_sensitive)
+ }
+
+ fn len_of_char_in_current_encoding(&self, c: char) -> usize {
+ self.as_ref().len_of_char_in_current_encoding(c)
+ }
+}
+
/// A helper struct to seek forwards and backwards in strings. Used by the tokenizer to read HTML
/// from strings.
pub struct StringReader<'a> {