]> git.lizzy.rs Git - rust.git/commitdiff
Add doc example to str::from_boxed_utf8_unchecked
authorTommy Ip <hkmp7tommy@gmail.com>
Mon, 11 Sep 2017 16:28:28 +0000 (17:28 +0100)
committerTommy Ip <hkmp7tommy@gmail.com>
Mon, 11 Sep 2017 16:28:28 +0000 (17:28 +0100)
Fixes #44463.

src/liballoc/str.rs

index f0c63a2eb55d5cb99f58c2861f8e3e7b2f428a4f..48b4d52a06aa95d7902e6bb6a134e1f2377e61e1 100644 (file)
@@ -2050,6 +2050,17 @@ pub fn repeat(&self, n: usize) -> String {
 
 /// 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)