about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorrwakulszowa <rwakulszowa1@gmail.com>2017-09-12 11:53:16 +0100
committerrwakulszowa <rwakulszowa1@gmail.com>2017-09-12 11:59:42 +0100
commitb8e0989445b3e29affa529d8f1b8574267fda495 (patch)
treeaebe933b12323dc92e1cbb81bcf3db6f826e5bb5 /src/liballoc
parentefa3ec67e28ab8a4c3377a039095cd464713cdfd (diff)
downloadrust-b8e0989445b3e29affa529d8f1b8574267fda495.tar.gz
rust-b8e0989445b3e29affa529d8f1b8574267fda495.zip
Add an example of std::str::encode_utf16
Closes #44419
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/str.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs
index f0c63a2eb55..a665480bba7 100644
--- a/src/liballoc/str.rs
+++ b/src/liballoc/str.rs
@@ -855,6 +855,19 @@ impl str {
     }
 
     /// Returns an iterator of `u16` over the string encoded as UTF-16.
+    ///
+    /// # Examples
+    ///
+    /// Basic usage:
+    ///
+    /// ```
+    /// let text = "Zażółć gęślą jaźń";
+    ///
+    /// let utf8_len = text.len();
+    /// let utf16_len = text.encode_utf16().count();
+    ///
+    /// assert!(utf16_len <= utf8_len);
+    /// ```
     #[stable(feature = "encode_utf16", since = "1.8.0")]
     pub fn encode_utf16(&self) -> EncodeUtf16 {
         EncodeUtf16 { encoder: Utf16Encoder::new(self[..].chars()) }