Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Fix FmtToIoWriter::write_str to call write_all
Browse files Browse the repository at this point in the history
Previously, the implementation could silently fail to write some
bytes. Now, the implementation should either write all the bytes or
return an error.

The docs for `std::fmt::Write::write_str` say, "This method can only
succeed if the entire string slice was successfully written, and this
method will not return until all data has been written or an error
occurs." So, `FmtToIoWriter::write_str` must call
`std::io::Write::write_all` instead of `std::io::Write::write` on the
inner writer in order to ensure that all the bytes are written.
  • Loading branch information
jturner314 committed Aug 18, 2021
1 parent 4684ca0 commit b6c38bf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ser.rs
Expand Up @@ -867,7 +867,7 @@ where
W: io::Write,
{
fn write_str(&mut self, s: &str) -> fmt::Result {
if self.writer.write(s.as_bytes()).is_err() {
if self.writer.write_all(s.as_bytes()).is_err() {
return Err(fmt::Error);
}
Ok(())
Expand Down

0 comments on commit b6c38bf

Please sign in to comment.