summaryrefslogtreecommitdiffstats
path: root/vendor/tinystr/src/ascii.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tinystr/src/ascii.rs')
-rw-r--r--vendor/tinystr/src/ascii.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/vendor/tinystr/src/ascii.rs b/vendor/tinystr/src/ascii.rs
index f39f39b73..9ab694f02 100644
--- a/vendor/tinystr/src/ascii.rs
+++ b/vendor/tinystr/src/ascii.rs
@@ -140,21 +140,23 @@ impl<const N: usize> TinyAsciiStr<N> {
pub const fn as_bytes(&self) -> &[u8] {
// Safe because `self.bytes.as_slice()` pointer-casts to `&[u8]`,
// and changing the length of that slice to self.len() < N is safe.
- unsafe { core::mem::transmute((self.bytes.as_slice().as_ptr(), self.len())) }
+ unsafe {
+ core::slice::from_raw_parts(self.bytes.as_slice().as_ptr() as *const u8, self.len())
+ }
}
#[inline]
#[must_use]
pub const fn all_bytes(&self) -> &[u8; N] {
// SAFETY: `self.bytes` has same size as [u8; N]
- unsafe { core::mem::transmute(&self.bytes) }
+ unsafe { &*(self.bytes.as_ptr() as *const [u8; N]) }
}
#[inline]
#[must_use]
- /// Resizes a TinyAsciiStr<N> to a TinyAsciiStr<M>.
+ /// Resizes a `TinyAsciiStr<N>` to a `TinyAsciiStr<M>`.
///
- /// If M < len() the string gets truncated, otherwise only the
+ /// If `M < len()` the string gets truncated, otherwise only the
/// memory representation changes.
pub const fn resize<const M: usize>(self) -> TinyAsciiStr<M> {
let mut bytes = [0; M];
@@ -729,7 +731,7 @@ mod test {
};
let expected = reference_f(&s);
let actual = tinystr_f(t);
- assert_eq!(expected, actual, "TinyAsciiStr<{}>: {:?}", N, s);
+ assert_eq!(expected, actual, "TinyAsciiStr<{N}>: {s:?}");
}
}