Skip to content

Commit 38a8d60

Browse files
authored
Rollup merge of #44497 - tommyip:doc_example, r=frewsxcv
Add doc example to str::from_boxed_utf8_unchecked Fixes #44463.
2 parents f90eabd + ede6dfd commit 38a8d60

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
@@ -2061,6 +2061,17 @@ impl str {
20612061

20622062
/// Converts a boxed slice of bytes to a boxed string slice without checking
20632063
/// that the string contains valid UTF-8.
2064+
///
2065+
/// # Examples
2066+
///
2067+
/// Basic usage:
2068+
///
2069+
/// ```
2070+
/// let smile_utf8 = Box::new([226, 152, 186]);
2071+
/// let smile = unsafe { std::str::from_boxed_utf8_unchecked(smile_utf8) };
2072+
///
2073+
/// assert_eq!("☺", &*smile);
2074+
/// ```
20642075
#[stable(feature = "str_box_extras", since = "1.20.0")]
20652076
pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box<str> {
20662077
mem::transmute(v)

0 commit comments

Comments
 (0)