Skip to content

Commit

Permalink
Add doc example to str::from_boxed_utf8_unchecked
Browse files Browse the repository at this point in the history
Fixes #44463.
  • Loading branch information
tommyip committed Sep 11, 2017
1 parent 19d30fc commit ede6dfd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/liballoc/str.rs
Expand Up @@ -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)
Expand Down

0 comments on commit ede6dfd

Please sign in to comment.