Skip to content

Commit f90eabd

Browse files
authored
Rollup merge of #44485 - 42triangles:master, r=frewsxcv
Added an example for `std::str::into_boxed_bytes()` This solves issue #44423.
2 parents 56ee7dc + f452acb commit f90eabd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/liballoc/str.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,17 @@ impl str {
17831783
}
17841784

17851785
/// Converts a `Box<str>` into a `Box<[u8]>` without copying or allocating.
1786+
///
1787+
/// # Examples
1788+
///
1789+
/// Basic usage:
1790+
///
1791+
/// ```
1792+
/// let s = "this is a string";
1793+
/// let boxed_str = s.to_owned().into_boxed_str();
1794+
/// let boxed_bytes = boxed_str.into_boxed_bytes();
1795+
/// assert_eq!(*boxed_bytes, *s.as_bytes());
1796+
/// ```
17861797
#[stable(feature = "str_box_extras", since = "1.20.0")]
17871798
pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> {
17881799
self.into()

0 commit comments

Comments
 (0)