Skip to content

Commit 8ca0212

Browse files
authored
Rollup merge of #44521 - rwakulszowa:str_utf16_doc, r=frewsxcv
Add an example of std::str::encode_utf16 Closes #44419
2 parents 38a8d60 + b8e0989 commit 8ca0212

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/liballoc/str.rs

+13
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,19 @@ impl str {
855855
}
856856

857857
/// Returns an iterator of `u16` over the string encoded as UTF-16.
858+
///
859+
/// # Examples
860+
///
861+
/// Basic usage:
862+
///
863+
/// ```
864+
/// let text = "Zażółć gęślą jaźń";
865+
///
866+
/// let utf8_len = text.len();
867+
/// let utf16_len = text.encode_utf16().count();
868+
///
869+
/// assert!(utf16_len <= utf8_len);
870+
/// ```
858871
#[stable(feature = "encode_utf16", since = "1.8.0")]
859872
pub fn encode_utf16(&self) -> EncodeUtf16 {
860873
EncodeUtf16 { encoder: Utf16Encoder::new(self[..].chars()) }

0 commit comments

Comments
 (0)