about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-09-14 22:32:42 -0400
committerGitHub <noreply@github.com>2017-09-14 22:32:42 -0400
commit592cafeb3df6e7aeb7d65a36be981f78b0f5e9e4 (patch)
treef7fda520decf1afc6111cef500506e85336e0b15
parent27b1097ba09576e609419c27e7e208836aad9659 (diff)
parent8adf50d90ecd7f7524e745c5d64edd203ebc737f (diff)
downloadrust-592cafeb3df6e7aeb7d65a36be981f78b0f5e9e4.tar.gz
rust-592cafeb3df6e7aeb7d65a36be981f78b0f5e9e4.zip
Rollup merge of #44477 - napen123:master, r=frewsxcv
Add doc examples to str::from_utf8_unchecked_mut

Fixes #44461
-rw-r--r--src/libcore/str/mod.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs
index ce331608390..d4fef45ae4e 100644
--- a/src/libcore/str/mod.rs
+++ b/src/libcore/str/mod.rs
@@ -413,6 +413,19 @@ pub unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
 /// See the immutable version, [`from_utf8_unchecked()`][fromutf8], for more information.
 ///
 /// [fromutf8]: fn.from_utf8_unchecked.html
+///
+/// # Examples
+///
+/// Basic usage:
+///
+/// ```
+/// use std::str;
+///
+/// let mut heart = vec![240, 159, 146, 150];
+/// let heart = unsafe { str::from_utf8_unchecked_mut(&mut heart) };
+///
+/// assert_eq!("💖", heart);
+/// ```
 #[inline]
 #[stable(feature = "str_mut_extras", since = "1.20.0")]
 pub unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str {