From 1e746e68f647eb42586ffab81fefa9f68723ed97 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Mon, 4 Sep 2023 08:28:11 +0200 Subject: feat: add blanket impl of Reader for boxed readers --- CHANGELOG.md | 4 ++++ src/reader.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) 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 Reader for Box { + type Error = R::Error; + + fn read_char(&mut self) -> Result, Self::Error> { + self.as_mut().read_char() + } + + fn try_read_string(&mut self, s: &str, case_sensitive: bool) -> Result { + 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> { -- cgit v1.2.3