]> git.lizzy.rs Git - rust.git/commitdiff
Clarify return type of `String::from_utf16_lossy`.
authorCorey Farwell <coreyf@rwell.org>
Thu, 14 Sep 2017 19:34:31 +0000 (15:34 -0400)
committerCorey Farwell <coreyf@rwell.org>
Thu, 14 Sep 2017 19:47:37 +0000 (15:47 -0400)
Fixes https://github.com/rust-lang/rust/issues/32874

src/liballoc/string.rs

index 1708f3e398756d493b22d8ec6c8810363c6ede06..088082c261aa7b4d4f51889b80547dcad96c9f42 100644 (file)
@@ -622,6 +622,13 @@ pub fn from_utf16(v: &[u16]) -> Result<String, FromUtf16Error> {
     /// Decode a UTF-16 encoded slice `v` into a `String`, replacing
     /// invalid data with the replacement character (U+FFFD).
     ///
+    /// Unlike [`from_utf8_lossy`] which returns a [`Cow<'a, str>`],
+    /// `from_utf16_lossy` returns a `String` since the UTF-16 to UTF-8
+    /// conversion requires a memory allocation.
+    ///
+    /// [`from_utf8_lossy`]: #method.from_utf8_lossy
+    /// [`Cow<'a, str>`]: ../borrow/enum.Cow.html
+    ///
     /// # Examples
     ///
     /// Basic usage: