1
Fork 0

Made formatting consistent with surrounding code

This commit is contained in:
rodrimati1992 2020-08-06 02:15:55 -03:00 committed by GitHub
commit 77d0d152cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -381,15 +381,12 @@ pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
Ok(unsafe { from_utf8_unchecked_mut(v) }) Ok(unsafe { from_utf8_unchecked_mut(v) })
} }
#[repr(C)] #[repr(C)]
union StrOrSlice<'a> { union StrOrSlice<'a> {
str: &'a str, str: &'a str,
slice: &'a [u8], slice: &'a [u8],
} }
/// Converts a slice of bytes to a string slice without checking /// Converts a slice of bytes to a string slice without checking
/// that the string contains valid UTF-8. /// that the string contains valid UTF-8.
/// ///
@ -429,10 +426,9 @@ union StrOrSlice<'a> {
pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str { pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
// SAFETY: the caller must guarantee that the bytes `v` are valid UTF-8. // SAFETY: the caller must guarantee that the bytes `v` are valid UTF-8.
// Also relies on `&str` and `&[u8]` having the same layout. // Also relies on `&str` and `&[u8]` having the same layout.
unsafe{ StrOrSlice{ slice: v }.str } unsafe { StrOrSlice { slice: v }.str }
} }
/// Converts a slice of bytes to a string slice without checking /// Converts a slice of bytes to a string slice without checking
/// that the string contains valid UTF-8; mutable version. /// that the string contains valid UTF-8; mutable version.
/// ///