From 833a9b567ae15d691455457a476480d422e6f7a7 Mon Sep 17 00:00:00 2001 From: 42triangles Date: Mon, 11 Sep 2017 08:13:57 +0200 Subject: [PATCH 1/2] Added an example for `std::str::into_boxed_bytes()` --- src/liballoc/str.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index f0c63a2eb55d5..c48ff3f5cc306 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -1783,6 +1783,17 @@ impl str { } /// Converts a `Box` 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) -> Box<[u8]> { self.into() From f452acbb5e18ae188bc28dc8ea685f6b4cb0d2df Mon Sep 17 00:00:00 2001 From: 42triangles Date: Mon, 11 Sep 2017 08:28:14 +0200 Subject: [PATCH 2/2] Removed trailing whitespace --- src/liballoc/str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index c48ff3f5cc306..d4dcf2066df19 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -1783,7 +1783,7 @@ impl str { } /// Converts a `Box` into a `Box<[u8]>` without copying or allocating. - /// + /// /// # Examples /// /// Basic usage: