Change comment to // Safety: ...

This changes a comment to be explicit on how it's safe we can avoid
validating UTF-8.
This commit is contained in:
Erick Tryzelaar 2022-11-09 22:41:28 +00:00
parent 15ec95a98d
commit 1050f6b808

View File

@ -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)
}