diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-09-14 22:32:45 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-14 22:32:45 -0400 |
| commit | 50240f80f15bfce48aea1c270009936646a9f83e (patch) | |
| tree | 7b3a74741a6a1f9a03e19e69c7ebb882a881e2e9 /src/liballoc | |
| parent | 1d361ff2a55c9a2ac80a657f7aebce10ee04b3bc (diff) | |
| parent | b8e0989445b3e29affa529d8f1b8574267fda495 (diff) | |
| download | rust-50240f80f15bfce48aea1c270009936646a9f83e.tar.gz rust-50240f80f15bfce48aea1c270009936646a9f83e.zip | |
Rollup merge of #44521 - rwakulszowa:str_utf16_doc, r=frewsxcv
Add an example of std::str::encode_utf16 Closes #44419
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/str.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 56aae1a1cc1..62b5f13675c 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()) } |
