about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorTommy Ip <hkmp7tommy@gmail.com>2017-09-11 17:28:28 +0100
committerTommy Ip <hkmp7tommy@gmail.com>2017-09-11 17:28:28 +0100
commitede6dfd72a601a1da403d10849f56791d2144b40 (patch)
treee7a805058c37f7a1732883d0fc9a05fb83c50e7f /src/liballoc
parent19d30fcdb28c2a4f57774b827b1a17ee156b5c56 (diff)
downloadrust-ede6dfd72a601a1da403d10849f56791d2144b40.tar.gz
rust-ede6dfd72a601a1da403d10849f56791d2144b40.zip
Add doc example to str::from_boxed_utf8_unchecked
Fixes #44463.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/str.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs
index f0c63a2eb55..48b4d52a06a 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<str> {
     mem::transmute(v)