We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 18d5b4d commit d848104Copy full SHA for d848104
src/ascii_str.rs
@@ -48,17 +48,17 @@ impl AsciiStr {
48
/// Converts `&self` to a `&str` slice.
49
#[inline]
50
#[must_use]
51
- pub fn as_str(&self) -> &str {
+ pub const fn as_str(&self) -> &str {
52
// SAFETY: All variants of `AsciiChar` are valid bytes for a `str`.
53
- unsafe { &*(self as *const AsciiStr as *const str) }
+ unsafe { mem::transmute(self) }
54
}
55
56
/// Converts `&self` into a byte slice.
57
58
59
- pub fn as_bytes(&self) -> &[u8] {
+ pub const fn as_bytes(&self) -> &[u8] {
60
// SAFETY: All variants of `AsciiChar` are valid `u8`, given they're `repr(u8)`.
61
- unsafe { &*(self as *const AsciiStr as *const [u8]) }
62
63
64
/// Returns the entire string as slice of `AsciiChar`s.
0 commit comments