Skip to content

Commit

Permalink
Rollup merge of rust-lang#44497 - tommyip:doc_example, r=frewsxcv
Browse files Browse the repository at this point in the history
Add doc example to str::from_boxed_utf8_unchecked

Fixes rust-lang#44463.
  • Loading branch information
frewsxcv committed Sep 14, 2017
2 parents f90eabd + ede6dfd commit 38a8d60
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 38a8d60

Please sign in to comment.