@@ -7,7 +7,7 @@ use std::path::Path;
77
88use memchr;
99
10- use crate :: errors:: { Error , Result } ;
10+ use crate :: errors:: { Error , Result , SyntaxError } ;
1111use crate :: events:: Event ;
1212use crate :: name:: QName ;
1313use crate :: reader:: { is_whitespace, BangType , ReadElementState , Reader , Span , XmlSource } ;
@@ -54,7 +54,7 @@ macro_rules! impl_buffered_source {
5454 byte: u8 ,
5555 buf: & ' b mut Vec <u8 >,
5656 position: & mut usize ,
57- ) -> Result <Option < & ' b [ u8 ] > > {
57+ ) -> Result <( & ' b [ u8 ] , bool ) > {
5858 // search byte must be within the ascii range
5959 debug_assert!( byte. is_ascii( ) ) ;
6060
@@ -90,18 +90,14 @@ macro_rules! impl_buffered_source {
9090 }
9191 * position += read;
9292
93- if read == 0 {
94- Ok ( None )
95- } else {
96- Ok ( Some ( & buf[ start..] ) )
97- }
93+ Ok ( ( & buf[ start..] , done) )
9894 }
9995
10096 $( $async) ? fn read_bang_element $( <$lf>) ? (
10197 & mut self ,
10298 buf: & ' b mut Vec <u8 >,
10399 position: & mut usize ,
104- ) -> Result <Option < ( BangType , & ' b [ u8 ] ) > > {
100+ ) -> Result <( BangType , & ' b [ u8 ] ) > {
105101 // Peeked one bang ('!') before being called, so it's guaranteed to
106102 // start with it.
107103 let start = buf. len( ) ;
@@ -115,7 +111,7 @@ macro_rules! impl_buffered_source {
115111 match self $( . $reader) ? . fill_buf( ) $( . $await) ? {
116112 // Note: Do not update position, so the error points to
117113 // somewhere sane rather than at the EOF
118- Ok ( n) if n. is_empty( ) => return Err ( bang_type . to_err ( ) ) ,
114+ Ok ( n) if n. is_empty( ) => break ,
119115 Ok ( available) => {
120116 // We only parse from start because we don't want to consider
121117 // whatever is in the buffer before the bang element
@@ -126,7 +122,7 @@ macro_rules! impl_buffered_source {
126122 read += used;
127123
128124 * position += read;
129- break ;
125+ return Ok ( ( bang_type , & buf [ start.. ] ) ) ;
130126 } else {
131127 buf. extend_from_slice( available) ;
132128
@@ -143,19 +139,15 @@ macro_rules! impl_buffered_source {
143139 }
144140 }
145141
146- if read == 0 {
147- Ok ( None )
148- } else {
149- Ok ( Some ( ( bang_type, & buf[ start..] ) ) )
150- }
142+ Err ( bang_type. to_err( ) )
151143 }
152144
153145 #[ inline]
154146 $( $async) ? fn read_element $( <$lf>) ? (
155147 & mut self ,
156148 buf: & ' b mut Vec <u8 >,
157149 position: & mut usize ,
158- ) -> Result <Option < & ' b [ u8 ] > > {
150+ ) -> Result <& ' b [ u8 ] > {
159151 let mut state = ReadElementState :: Elem ;
160152 let mut read = 0 ;
161153
@@ -172,7 +164,7 @@ macro_rules! impl_buffered_source {
172164
173165 // Position now just after the `>` symbol
174166 * position += read;
175- break ;
167+ return Ok ( & buf [ start.. ] ) ;
176168 } else {
177169 // The `>` symbol not yet found, continue reading
178170 buf. extend_from_slice( available) ;
@@ -190,11 +182,7 @@ macro_rules! impl_buffered_source {
190182 } ;
191183 }
192184
193- if read == 0 {
194- Ok ( None )
195- } else {
196- Ok ( Some ( & buf[ start..] ) )
197- }
185+ Err ( Error :: Syntax ( SyntaxError :: UnclosedTag ) )
198186 }
199187
200188 $( $async) ? fn skip_whitespace( & mut self , position: & mut usize ) -> Result <( ) > {
0 commit comments