Skip to content

Commit

Permalink
Change comment to // Safety: ...
Browse files Browse the repository at this point in the history
This changes a comment to be explicit on how it's safe we can avoid
validating UTF-8.
  • Loading branch information
erickt committed Nov 9, 2022
1 parent 15ec95a commit 1050f6b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,9 @@ impl Serialize for net::Ipv4Addr {
// Skip over delimiters that we initialized buf with
written += format_u8(*oct, &mut buf[written + 1..]) + 1;
}
// We've only written ASCII bytes to the buffer, so it is valid UTF-8
serializer.serialize_str(unsafe { str::from_utf8_unchecked(&buf[..written]) })
// Safety: We've only written ASCII bytes to the buffer, so it is valid UTF-8
let buf = unsafe { str::from_utf8_unchecked(&buf[..written]) };
serializer.serialize_str(buf)
} else {
self.octets().serialize(serializer)
}
Expand Down

0 comments on commit 1050f6b

Please sign in to comment.