Skip to content

Commit

Permalink
Rollup merge of rust-lang#44485 - 42triangles:master, r=frewsxcv
Browse files Browse the repository at this point in the history
Added an example for `std::str::into_boxed_bytes()`

This solves issue rust-lang#44423.
  • Loading branch information
frewsxcv authored Sep 15, 2017
2 parents 592cafe + f452acb commit e3c4b8c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e3c4b8c

Please sign in to comment.