mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-12 22:31:02 +00:00
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:
@@ -736,8 +736,9 @@ impl Serialize for net::Ipv4Addr {
|
|||||||
// Skip over delimiters that we initialized buf with
|
// Skip over delimiters that we initialized buf with
|
||||||
written += format_u8(*oct, &mut buf[written + 1..]) + 1;
|
written += format_u8(*oct, &mut buf[written + 1..]) + 1;
|
||||||
}
|
}
|
||||||
// We've only written ASCII bytes to the buffer, so it is valid UTF-8
|
// Safety: 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]) })
|
let buf = unsafe { str::from_utf8_unchecked(&buf[..written]) };
|
||||||
|
serializer.serialize_str(buf)
|
||||||
} else {
|
} else {
|
||||||
self.octets().serialize(serializer)
|
self.octets().serialize(serializer)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user