Skip to content

Commit

Permalink
Elaborate on StrRead::parse_str safety comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 23, 2021
1 parent 379412b commit 33c3134
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,9 @@ impl<'a> Read<'a> for StrRead<'a> {

fn parse_str<'s>(&'s mut self, scratch: &'s mut Vec<u8>) -> Result<Reference<'a, 's, str>> {
self.delegate.parse_str_bytes(scratch, true, |_, bytes| {
// The input is assumed to be valid UTF-8 and the \u-escapes are
// checked along the way, so don't need to check here.
// The deserialization input came in as &str with a UTF-8 guarantee,
// and the \u-escapes are checked along the way, so don't need to
// check here.
Ok(unsafe { str::from_utf8_unchecked(bytes) })
})
}
Expand Down

0 comments on commit 33c3134

Please sign in to comment.