Skip to content

Commit 4003c50

Browse files
tinou98dtolnay
authored andcommitted
Add Read implementation for &mut Read
1 parent fdc177d commit 4003c50

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

‎src/read.rs‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,84 @@ pub trait Read<'de>: private::Sealed {
111111
fn set_failed(&mut self, failed: &mut bool);
112112
}
113113

114+
impl<'de, R: Read<'de>> private::Sealed for &mut R {}
115+
impl<'de, R: Read<'de>> Read<'de> for &mut R {
116+
#[inline]
117+
fn next(&mut self) -> Result<Option<u8>> {
118+
R::next(self)
119+
}
120+
121+
#[inline]
122+
fn peek(&mut self) -> Result<Option<u8>> {
123+
R::peek(self)
124+
}
125+
126+
#[inline]
127+
fn discard(&mut self) {
128+
R::discard(self)
129+
}
130+
131+
#[inline]
132+
fn position(&self) -> Position {
133+
R::position(self)
134+
}
135+
136+
#[inline]
137+
fn peek_position(&self) -> Position {
138+
R::peek_position(self)
139+
}
140+
141+
#[inline]
142+
fn byte_offset(&self) -> usize {
143+
R::byte_offset(self)
144+
}
145+
146+
#[inline]
147+
fn parse_str<'s>(&'s mut self, scratch: &'s mut Vec<u8>) -> Result<Reference<'de, 's, str>> {
148+
R::parse_str(self, scratch)
149+
}
150+
151+
#[inline]
152+
fn parse_str_raw<'s>(
153+
&'s mut self,
154+
scratch: &'s mut Vec<u8>,
155+
) -> Result<Reference<'de, 's, [u8]>> {
156+
R::parse_str_raw(self, scratch)
157+
}
158+
159+
#[inline]
160+
fn ignore_str(&mut self) -> Result<()> {
161+
R::ignore_str(self)
162+
}
163+
164+
#[inline]
165+
fn decode_hex_escape(&mut self) -> Result<u16> {
166+
R::decode_hex_escape(self)
167+
}
168+
169+
#[cfg(feature = "raw_value")]
170+
#[inline]
171+
fn begin_raw_buffering(&mut self) {
172+
R::begin_raw_buffering(self)
173+
}
174+
175+
#[cfg(feature = "raw_value")]
176+
#[inline]
177+
fn end_raw_buffering<V>(&mut self, visitor: V) -> Result<V::Value>
178+
where
179+
V: Visitor<'de>,
180+
{
181+
R::end_raw_buffering(self, visitor)
182+
}
183+
184+
const should_early_return_if_failed: bool = R::should_early_return_if_failed;
185+
186+
#[inline]
187+
fn set_failed(&mut self, failed: &mut bool) {
188+
R::set_failed(self, failed)
189+
}
190+
}
191+
114192
pub struct Position {
115193
pub line: usize,
116194
pub column: usize,

0 commit comments

Comments
 (0)