From 5d402ce5a8923484b95719b9cac98f81b7e7e328 Mon Sep 17 00:00:00 2001 From: bendn Date: Sun, 29 Oct 2023 15:19:43 +0700 Subject: [PATCH 1/2] cow from array --- library/alloc/src/vec/cow.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/alloc/src/vec/cow.rs b/library/alloc/src/vec/cow.rs index 2c799605b7b67..bef2ab271c355 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]> { } } +#[stable(feature = "cow_from_array", since = "1.8.0")] +impl<'a, const N: usize, T: Clone> From<&'a [T; N]> for Cow<'a, [T]> { + /// Creates a [`Borrowed`] variant of [`Cow`] + /// from a 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) + } +} + #[stable(feature = "cow_from_vec", since = "1.8.0")] impl<'a, T: Clone> From> for Cow<'a, [T]> { /// Creates an [`Owned`] variant of [`Cow`] From 1935bf7791e264fbf4739ef45a2eb4ee4e1a89c1 Mon Sep 17 00:00:00 2001 From: bendn Date: Sun, 12 Nov 2023 05:29:24 +0700 Subject: [PATCH 2/2] change since fieled Co-authored-by: zachs18 <8355914+zachs18@users.noreply.github.com> --- library/alloc/src/vec/cow.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/vec/cow.rs b/library/alloc/src/vec/cow.rs index bef2ab271c355..069b1662a8cfa 100644 --- a/library/alloc/src/vec/cow.rs +++ b/library/alloc/src/vec/cow.rs @@ -15,7 +15,7 @@ impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> { } } -#[stable(feature = "cow_from_array", since = "1.8.0")] +#[stable(feature = "cow_from_array", since = "CURRENT_RUSTC_VERSION")] impl<'a, const N: usize, T: Clone> From<&'a [T; N]> for Cow<'a, [T]> { /// Creates a [`Borrowed`] variant of [`Cow`] /// from a array.