Skip to content

Commit 31177ec

Browse files
committed
Remove Result from methods that cannot generate errors for clarity
1 parent 573df5e commit 31177ec

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/reader/mod.rs

+4-4
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

+9-9
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
if let Some(content) = content.strip_suffix(b"/") {
262262
// This is self-closed tag `<something/>`
263263
let event = BytesStart::wrap(content, name_len(content));
@@ -266,9 +266,9 @@ impl ReaderState {
266266
self.state = ParseState::InsideEmpty;
267267
self.opened_starts.push(self.opened_buffer.len());
268268
self.opened_buffer.extend(event.name().as_ref());
269-
Ok(Event::Start(event))
269+
Event::Start(event)
270270
} else {
271-
Ok(Event::Empty(event))
271+
Event::Empty(event)
272272
}
273273
} else {
274274
let event = BytesStart::wrap(content, name_len(content));
@@ -278,17 +278,17 @@ impl ReaderState {
278278
// enabled, we should have that information
279279
self.opened_starts.push(self.opened_buffer.len());
280280
self.opened_buffer.extend(event.name().as_ref());
281-
Ok(Event::Start(event))
281+
Event::Start(event)
282282
}
283283
}
284284

285285
#[inline]
286-
pub fn close_expanded_empty(&mut self) -> Result<Event<'static>> {
286+
pub fn close_expanded_empty(&mut self) -> BytesEnd<'static> {
287287
self.state = ParseState::InsideText;
288288
let name = self
289289
.opened_buffer
290290
.split_off(self.opened_starts.pop().unwrap());
291-
Ok(Event::End(BytesEnd::wrap(name.into())))
291+
BytesEnd::wrap(name.into())
292292
}
293293

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

0 commit comments

Comments
 (0)