Merge pull request #2329 from dtolnay/safety
Revert Buf::as_str safety change from PR 2319
This commit is contained in:
commit
fabbd2b097
@ -1,7 +1,7 @@
|
||||
use lib::fmt::{self, Write};
|
||||
use lib::str;
|
||||
|
||||
pub struct Buf<'a> {
|
||||
pub(super) struct Buf<'a> {
|
||||
bytes: &'a mut [u8],
|
||||
offset: usize,
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user