]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #44485 - 42triangles:master, r=frewsxcv
authorCorey Farwell <coreyf@rwell.org>
Fri, 15 Sep 2017 02:32:43 +0000 (22:32 -0400)
committerGitHub <noreply@github.com>
Fri, 15 Sep 2017 02:32:43 +0000 (22:32 -0400)
Added an example for `std::str::into_boxed_bytes()`

This solves issue #44423.

src/liballoc/str.rs

index f0c63a2eb55d5cb99f58c2861f8e3e7b2f428a4f..d4dcf2066df19a6399e0f1751f8e9be07f00cd2d 100644 (file)
@@ -1783,6 +1783,17 @@ pub fn parse<F: FromStr>(&self) -> Result<F, F::Err> {
     }
 
     /// Converts a `Box<str>` into a `Box<[u8]>` without copying or allocating.
+    ///
+    /// # Examples
+    ///
+    /// Basic usage:
+    ///
+    /// ```
+    /// let s = "this is a string";
+    /// let boxed_str = s.to_owned().into_boxed_str();
+    /// let boxed_bytes = boxed_str.into_boxed_bytes();
+    /// assert_eq!(*boxed_bytes, *s.as_bytes());
+    /// ```
     #[stable(feature = "str_box_extras", since = "1.20.0")]
     pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> {
         self.into()