Skip to content

Commit

Permalink
Simplify serialize_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 11, 2023
1 parent 0e2c949 commit 44b4a6c
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,31 +192,22 @@ where
.formatter
.begin_array(&mut self.writer)
.map_err(Error::io));
if value.is_empty() {
let mut first = true;
for byte in value {
tri!(self
.formatter
.end_array(&mut self.writer)
.begin_array_value(&mut self.writer, first)
.map_err(Error::io));
} else {
let mut state = State::First;
for byte in value {
tri!(self
.formatter
.begin_array_value(&mut self.writer, state == State::First)
.map_err(Error::io));
state = State::Rest;
tri!(byte.serialize(&mut *self));
tri!(self
.formatter
.end_array_value(&mut self.writer)
.map_err(Error::io));
}
tri!(byte.serialize(&mut *self));
tri!(self
.formatter
.end_array(&mut self.writer)
.end_array_value(&mut self.writer)
.map_err(Error::io));
first = false;
}
Ok(())
self.formatter
.end_array(&mut self.writer)
.map_err(Error::io)
}

#[inline]
Expand Down

0 comments on commit 44b4a6c

Please sign in to comment.