diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-09-14 22:32:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-14 22:32:44 -0400 |
| commit | 1d361ff2a55c9a2ac80a657f7aebce10ee04b3bc (patch) | |
| tree | 80af72cdba9f4f705fdb62c4cfd832815e7a9775 /src/liballoc | |
| parent | e3c4b8c43a82f6d6d326ece15d7c08c31d221020 (diff) | |
| parent | ede6dfd72a601a1da403d10849f56791d2144b40 (diff) | |
| download | rust-1d361ff2a55c9a2ac80a657f7aebce10ee04b3bc.tar.gz rust-1d361ff2a55c9a2ac80a657f7aebce10ee04b3bc.zip | |
Rollup merge of #44497 - tommyip:doc_example, r=frewsxcv
Add doc example to str::from_boxed_utf8_unchecked Fixes #44463.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/str.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index d4dcf2066df..56aae1a1cc1 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -2061,6 +2061,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) |
