Skip to content

Commit a7183cf

Browse files
Rollup merge of rust-lang#44477 - napen123:master, r=frewsxcv
Add doc examples to str::from_utf8_unchecked_mut Fixes rust-lang#44461
2 parents d318148 + 8adf50d commit a7183cf

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libcore/str/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,19 @@ pub unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
413413
/// See the immutable version, [`from_utf8_unchecked()`][fromutf8], for more information.
414414
///
415415
/// [fromutf8]: fn.from_utf8_unchecked.html
416+
///
417+
/// # Examples
418+
///
419+
/// Basic usage:
420+
///
421+
/// ```
422+
/// use std::str;
423+
///
424+
/// let mut heart = vec![240, 159, 146, 150];
425+
/// let heart = unsafe { str::from_utf8_unchecked_mut(&mut heart) };
426+
///
427+
/// assert_eq!("💖", heart);
428+
/// ```
416429
#[inline]
417430
#[stable(feature = "str_mut_extras", since = "1.20.0")]
418431
pub unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str {

0 commit comments

Comments
 (0)