diff options
| author | Tristan Guichaoua <tguichaoua.dev@gmail.com> | 2023-07-08 19:55:33 +0200 |
|---|---|---|
| committer | Tristan Guichaoua <tguichaoua.dev@gmail.com> | 2023-07-08 19:55:33 +0200 |
| commit | bab8d29887a0d801fe72f922dafe75a635bc9198 (patch) | |
| tree | 202f46c9c7f209dd5e990081279c55173bbdcc9c | |
| parent | 9bb6fbe26198e58b517bfbf58a3348fad98d1654 (diff) | |
| download | rust-bab8d29887a0d801fe72f922dafe75a635bc9198.tar.gz rust-bab8d29887a0d801fe72f922dafe75a635bc9198.zip | |
impl `From<&[T; N]>` for `Cow<[T]>`
| -rw-r--r-- | library/alloc/src/vec/cow.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/library/alloc/src/vec/cow.rs b/library/alloc/src/vec/cow.rs index 2c799605b7b..7d2462ee32e 100644 --- a/library/alloc/src/vec/cow.rs +++ b/library/alloc/src/vec/cow.rs @@ -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`] |
