Skip to content

Commit

Permalink
Add documentation to Box conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
timClicks committed Oct 8, 2021
1 parent 6dd7fa1 commit 78810bd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,10 +1333,15 @@ impl<T: Copy> From<&[T]> for Box<[T]> {
impl<T: Copy> From<Cow<'_, [T]>> for Box<[T]> {
/// Converts a `Cow<'_, [T]>` into a `Box<[T]>`
///
<<<<<<< HEAD
/// When `cow` is the `Cow::Borrowed` variant, this
/// conversion allocates on the heap and performs a copy of the
/// underlying slice. Otherwise, it will try to re-use the owned
/// vec's allocation.
=======
/// This conversion allocates on the heap
/// and performs a copy of `s`.
>>>>>>> Add documentation to Box conversions
#[inline]
fn from(cow: Cow<'_, [T]>) -> Box<[T]> {
match cow {
Expand Down Expand Up @@ -1455,7 +1460,8 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
///
/// # Errors
///
/// Returns the old `Box<[T]>` in the `Err` variant if `boxed_slice.len()` does not equal `N`.
/// Returns the old `Box<[T]>` in the `Err` variant if
/// `boxed_slice.len()` does not equal `N`.
fn try_from(boxed_slice: Box<[T]>) -> Result<Self, Self::Error> {
if boxed_slice.len() == N {
Ok(unsafe { Box::from_raw(Box::into_raw(boxed_slice) as *mut [T; N]) })
Expand Down

0 comments on commit 78810bd

Please sign in to comment.