Skip to content

Commit

Permalink
Rollup merge of rust-lang#44521 - rwakulszowa:str_utf16_doc, r=frewsxcv
Browse files Browse the repository at this point in the history
Add an example of std::str::encode_utf16

Closes rust-lang#44419
  • Loading branch information
frewsxcv authored Sep 14, 2017
2 parents 38a8d60 + b8e0989 commit 8ca0212
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand Down

0 comments on commit 8ca0212

Please sign in to comment.