diff options
| author | 42triangles <dodo2998@gmail.com> | 2017-09-11 08:13:57 +0200 |
|---|---|---|
| committer | 42triangles <dodo2998@gmail.com> | 2017-09-11 08:13:57 +0200 |
| commit | 833a9b567ae15d691455457a476480d422e6f7a7 (patch) | |
| tree | 169b9642f4bde4ea60ec7ed59ac0dc8217e5f075 /src/liballoc | |
| parent | e6bce95094facf5bf36afa5995f522d374d00149 (diff) | |
| download | rust-833a9b567ae15d691455457a476480d422e6f7a7.tar.gz rust-833a9b567ae15d691455457a476480d422e6f7a7.zip | |
Added an example for `std::str::into_boxed_bytes()`
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..c48ff3f5cc3 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() |
