Added an example for std::str::into_boxed_bytes()
This commit is contained in:
parent
e6bce95094
commit
833a9b567a
1 changed files with 11 additions and 0 deletions
|
@ -1783,6 +1783,17 @@ impl str {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a `Box<str>` into a `Box<[u8]>` without copying or allocating.
|
/// 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")]
|
#[stable(feature = "str_box_extras", since = "1.20.0")]
|
||||||
pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> {
|
pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> {
|
||||||
self.into()
|
self.into()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue