@@ -7,7 +7,7 @@ use std::path::Path;
7
7
8
8
use memchr;
9
9
10
- use crate :: errors:: { Error , Result } ;
10
+ use crate :: errors:: { Error , Result , SyntaxError } ;
11
11
use crate :: events:: Event ;
12
12
use crate :: name:: QName ;
13
13
use crate :: reader:: { is_whitespace, BangType , ReadElementState , Reader , Span , XmlSource } ;
@@ -54,7 +54,7 @@ macro_rules! impl_buffered_source {
54
54
byte: u8 ,
55
55
buf: & ' b mut Vec <u8 >,
56
56
position: & mut usize ,
57
- ) -> Result <Option < & ' b [ u8 ] > > {
57
+ ) -> Result <( & ' b [ u8 ] , bool ) > {
58
58
// search byte must be within the ascii range
59
59
debug_assert!( byte. is_ascii( ) ) ;
60
60
@@ -90,18 +90,14 @@ macro_rules! impl_buffered_source {
90
90
}
91
91
* position += read;
92
92
93
- if read == 0 {
94
- Ok ( None )
95
- } else {
96
- Ok ( Some ( & buf[ start..] ) )
97
- }
93
+ Ok ( ( & buf[ start..] , done) )
98
94
}
99
95
100
96
$( $async) ? fn read_bang_element $( <$lf>) ? (
101
97
& mut self ,
102
98
buf: & ' b mut Vec <u8 >,
103
99
position: & mut usize ,
104
- ) -> Result <Option < ( BangType , & ' b [ u8 ] ) > > {
100
+ ) -> Result <( BangType , & ' b [ u8 ] ) > {
105
101
// Peeked one bang ('!') before being called, so it's guaranteed to
106
102
// start with it.
107
103
let start = buf. len( ) ;
@@ -115,7 +111,7 @@ macro_rules! impl_buffered_source {
115
111
match self $( . $reader) ? . fill_buf( ) $( . $await) ? {
116
112
// Note: Do not update position, so the error points to
117
113
// 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 ,
119
115
Ok ( available) => {
120
116
// We only parse from start because we don't want to consider
121
117
// whatever is in the buffer before the bang element
@@ -126,7 +122,7 @@ macro_rules! impl_buffered_source {
126
122
read += used;
127
123
128
124
* position += read;
129
- break ;
125
+ return Ok ( ( bang_type , & buf [ start.. ] ) ) ;
130
126
} else {
131
127
buf. extend_from_slice( available) ;
132
128
@@ -143,19 +139,15 @@ macro_rules! impl_buffered_source {
143
139
}
144
140
}
145
141
146
- if read == 0 {
147
- Ok ( None )
148
- } else {
149
- Ok ( Some ( ( bang_type, & buf[ start..] ) ) )
150
- }
142
+ Err ( bang_type. to_err( ) )
151
143
}
152
144
153
145
#[ inline]
154
146
$( $async) ? fn read_element $( <$lf>) ? (
155
147
& mut self ,
156
148
buf: & ' b mut Vec <u8 >,
157
149
position: & mut usize ,
158
- ) -> Result <Option < & ' b [ u8 ] > > {
150
+ ) -> Result <& ' b [ u8 ] > {
159
151
let mut state = ReadElementState :: Elem ;
160
152
let mut read = 0 ;
161
153
@@ -172,7 +164,7 @@ macro_rules! impl_buffered_source {
172
164
173
165
// Position now just after the `>` symbol
174
166
* position += read;
175
- break ;
167
+ return Ok ( & buf [ start.. ] ) ;
176
168
} else {
177
169
// The `>` symbol not yet found, continue reading
178
170
buf. extend_from_slice( available) ;
@@ -190,11 +182,7 @@ macro_rules! impl_buffered_source {
190
182
} ;
191
183
}
192
184
193
- if read == 0 {
194
- Ok ( None )
195
- } else {
196
- Ok ( Some ( & buf[ start..] ) )
197
- }
185
+ Err ( Error :: Syntax ( SyntaxError :: UnclosedTag ) )
198
186
}
199
187
200
188
$( $async) ? fn skip_whitespace( & mut self , position: & mut usize ) -> Result <( ) > {
0 commit comments