Skip to content

Commit 3aae3af

Browse files
committed
Remove Result from methods that cannot generate errors for clarity
1 parent 077de0e commit 3aae3af

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/reader/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,19 @@ macro_rules! read_event_impl {
245245
ReadTextResult::UpToMarkup(bytes) => {
246246
$self.state.state = ParseState::InsideMarkup;
247247
// Return Text event with `bytes` content or Eof if bytes is empty
248-
$self.state.emit_text(bytes)
248+
Ok($self.state.emit_text(bytes))
249249
}
250250
ReadTextResult::UpToEof(bytes) => {
251251
$self.state.state = ParseState::Done;
252252
// Return Text event with `bytes` content or Eof if bytes is empty
253-
$self.state.emit_text(bytes)
253+
Ok($self.state.emit_text(bytes))
254254
}
255255
ReadTextResult::Err(e) => Err(Error::Io(e.into())),
256256
}
257257
},
258258
// Go to InsideText state in next two arms
259259
ParseState::InsideMarkup => $self.$read_until_close($buf) $(.$await)?,
260-
ParseState::InsideEmpty => $self.state.close_expanded_empty(),
260+
ParseState::InsideEmpty => Ok(Event::End($self.state.close_expanded_empty())),
261261
ParseState::Done => Ok(Event::Eof),
262262
};
263263
};
@@ -348,7 +348,7 @@ macro_rules! read_until_close {
348348
.read_with(ElementParser::default(), $buf, &mut $self.state.offset)
349349
$(.$await)?
350350
{
351-
Ok(bytes) => $self.state.emit_start(bytes),
351+
Ok(bytes) => Ok($self.state.emit_start(bytes)),
352352
Err(e) => Err(e),
353353
},
354354
// `<` - syntax error, tag not closed

src/reader/state.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl ReaderState {
6060
///
6161
/// [`Text`]: Event::Text
6262
/// [`Eof`]: Event::Eof
63-
pub fn emit_text<'b>(&mut self, bytes: &'b [u8]) -> Result<Event<'b>> {
63+
pub fn emit_text<'b>(&mut self, bytes: &'b [u8]) -> Event<'b> {
6464
let mut content = bytes;
6565

6666
if self.config.trim_text_end {
@@ -73,9 +73,9 @@ impl ReaderState {
7373
}
7474

7575
if content.is_empty() {
76-
Ok(Event::Eof)
76+
Event::Eof
7777
} else {
78-
Ok(Event::Text(BytesText::wrap(content, self.decoder())))
78+
Event::Text(BytesText::wrap(content, self.decoder()))
7979
}
8080
}
8181

@@ -257,7 +257,7 @@ impl ReaderState {
257257
///
258258
/// # Parameters
259259
/// - `content`: Content of a tag between `<` and `>`
260-
pub fn emit_start<'b>(&mut self, content: &'b [u8]) -> Result<Event<'b>> {
260+
pub fn emit_start<'b>(&mut self, content: &'b [u8]) -> Event<'b> {
261261
let len = content.len();
262262
let name_end = content
263263
.iter()
@@ -272,27 +272,27 @@ impl ReaderState {
272272
self.state = ParseState::InsideEmpty;
273273
self.opened_starts.push(self.opened_buffer.len());
274274
self.opened_buffer.extend(&content[..name_len]);
275-
Ok(Event::Start(event))
275+
Event::Start(event)
276276
} else {
277-
Ok(Event::Empty(event))
277+
Event::Empty(event)
278278
}
279279
} else {
280280
// #514: Always store names event when .check_end_names == false,
281281
// because checks can be temporary disabled and when they would be
282282
// enabled, we should have that information
283283
self.opened_starts.push(self.opened_buffer.len());
284284
self.opened_buffer.extend(&content[..name_end]);
285-
Ok(Event::Start(BytesStart::wrap(content, name_end)))
285+
Event::Start(BytesStart::wrap(content, name_end))
286286
}
287287
}
288288

289289
#[inline]
290-
pub fn close_expanded_empty(&mut self) -> Result<Event<'static>> {
290+
pub fn close_expanded_empty(&mut self) -> BytesEnd<'static> {
291291
self.state = ParseState::InsideText;
292292
let name = self
293293
.opened_buffer
294294
.split_off(self.opened_starts.pop().unwrap());
295-
Ok(Event::End(BytesEnd::wrap(name.into())))
295+
BytesEnd::wrap(name.into())
296296
}
297297

298298
/// Get the decoder, used to decode bytes, read by this reader, to the strings.

0 commit comments

Comments
 (0)