Skip to content

Commit 8804742

Browse files
Add impl AsMut<str> for AsciiChar
1 parent 3f04fd5 commit 8804742

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

library/core/src/ascii/ascii_char.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,18 @@ impl AsRef<str> for AsciiChar {
11771177
}
11781178
}
11791179

1180+
#[unstable(feature = "ascii_char", issue = "110998")]
1181+
impl AsMut<str> for AsciiChar {
1182+
#[inline(always)]
1183+
fn as_mut(&mut self) -> &mut str {
1184+
let ascii_ptr: *mut [Self] = crate::slice::from_mut(self);
1185+
let str_ptr = ascii_ptr as *mut str;
1186+
// SAFETY: Each ASCII codepoint in UTF-8 is encoded as one single-byte
1187+
// code unit having the same value as the ASCII byte.
1188+
unsafe { &mut *str_ptr }
1189+
}
1190+
}
1191+
11801192
impl [AsciiChar] {
11811193
/// Views this slice of ASCII characters as a UTF-8 `str`.
11821194
#[unstable(feature = "ascii_char", issue = "110998")]

0 commit comments

Comments
 (0)