Skip to content

Commit

Permalink
impl From<&[T; N]> for Cow<[T]>
Browse files Browse the repository at this point in the history
  • Loading branch information
tguichaoua committed Jan 18, 2024
1 parent 25f8d01 commit 7205640
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions library/alloc/src/vec/cow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
}
}

#[unstable(feature = "cow_from_array_ref", issue = "none")]
impl<'a, T: Clone, const N: usize> From<&'a [T; N]> for Cow<'a, [T]> {
/// Creates a [`Borrowed`] variant of [`Cow`]
/// from a reference to an array.
///
/// This conversion does not allocate or clone the data.
///
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
fn from(s: &'a [T; N]) -> Cow<'a, [T]> {
Cow::Borrowed(s as &[_])
}
}

#[stable(feature = "cow_from_vec", since = "1.8.0")]
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
/// Creates an [`Owned`] variant of [`Cow`]
Expand Down

0 comments on commit 7205640

Please sign in to comment.