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
GuillaumeGomez authored Sep 13, 2017
2 parents be19ea3 + b8e0989 commit 0aade70
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 0aade70

Please sign in to comment.