diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-09-14 22:32:43 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-14 22:32:43 -0400 |
| commit | e3c4b8c43a82f6d6d326ece15d7c08c31d221020 (patch) | |
| tree | 723e7b6da83260fe93df7b792720b520da63dd6c /src/liballoc | |
| parent | 592cafeb3df6e7aeb7d65a36be981f78b0f5e9e4 (diff) | |
| parent | f452acbb5e18ae188bc28dc8ea685f6b4cb0d2df (diff) | |
| download | rust-e3c4b8c43a82f6d6d326ece15d7c08c31d221020.tar.gz rust-e3c4b8c43a82f6d6d326ece15d7c08c31d221020.zip | |
Rollup merge of #44485 - 42triangles:master, r=frewsxcv
Added an example for `std::str::into_boxed_bytes()` This solves issue #44423.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/str.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index f0c63a2eb55..d4dcf2066df 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -1783,6 +1783,17 @@ impl str { } /// 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() |
