Skip to content

Commit ede6dfd

Browse files
committed
Add doc example to str::from_boxed_utf8_unchecked
Fixes #44463.
1 parent 19d30fc commit ede6dfd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/liballoc/str.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,17 @@ impl str {
20502050

20512051
/// Converts a boxed slice of bytes to a boxed string slice without checking
20522052
/// that the string contains valid UTF-8.
2053+
///
2054+
/// # Examples
2055+
///
2056+
/// Basic usage:
2057+
///
2058+
/// ```
2059+
/// let smile_utf8 = Box::new([226, 152, 186]);
2060+
/// let smile = unsafe { std::str::from_boxed_utf8_unchecked(smile_utf8) };
2061+
///
2062+
/// assert_eq!("☺", &*smile);
2063+
/// ```
20532064
#[stable(feature = "str_box_extras", since = "1.20.0")]
20542065
pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box<str> {
20552066
mem::transmute(v)

0 commit comments

Comments
 (0)