From ede6dfd72a601a1da403d10849f56791d2144b40 Mon Sep 17 00:00:00 2001 From: Tommy Ip Date: Mon, 11 Sep 2017 17:28:28 +0100 Subject: [PATCH] Add doc example to str::from_boxed_utf8_unchecked Fixes #44463. --- src/liballoc/str.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index f0c63a2eb55d5..48b4d52a06aa9 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -2050,6 +2050,17 @@ impl str { /// Converts a boxed slice of bytes to a boxed string slice without checking /// that the string contains valid UTF-8. +/// +/// # Examples +/// +/// Basic usage: +/// +/// ``` +/// let smile_utf8 = Box::new([226, 152, 186]); +/// let smile = unsafe { std::str::from_boxed_utf8_unchecked(smile_utf8) }; +/// +/// assert_eq!("☺", &*smile); +/// ``` #[stable(feature = "str_box_extras", since = "1.20.0")] pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box { mem::transmute(v)