Skip to content

Commit bab8d29

Browse files
committed
impl From<&[T; N]> for Cow<[T]>
1 parent 9bb6fbe commit bab8d29

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/alloc/src/vec/cow.rs

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
1515
}
1616
}
1717

18+
#[unstable(feature = "cow_from_array_ref", issue = "none")]
19+
impl<'a, T: Clone, const N: usize> From<&'a [T; N]> for Cow<'a, [T]> {
20+
/// Creates a [`Borrowed`] variant of [`Cow`]
21+
/// from a reference to an array.
22+
///
23+
/// This conversion does not allocate or clone the data.
24+
///
25+
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
26+
fn from(s: &'a [T; N]) -> Cow<'a, [T]> {
27+
Cow::Borrowed(s as &[_])
28+
}
29+
}
30+
1831
#[stable(feature = "cow_from_vec", since = "1.8.0")]
1932
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
2033
/// Creates an [`Owned`] variant of [`Cow`]

0 commit comments

Comments
 (0)