From f4df5e1e5a109976f9f6af4971a459d6bcac4783 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 4 Sep 2023 16:34:53 -0600 Subject: [PATCH] hybrid-array: looser `Clone` and `Copy` bounds on `Array` Switches from derived impls of `Clone` and `Copy` to handwritten ones which use the minimal required bounds for the underlying types. --- hybrid-array/src/lib.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/hybrid-array/src/lib.rs b/hybrid-array/src/lib.rs index 84abb902..3306c24e 100644 --- a/hybrid-array/src/lib.rs +++ b/hybrid-array/src/lib.rs @@ -38,7 +38,7 @@ use typenum::Unsigned; /// /// Provides the flexibility of typenum-based expressions while also /// allowing interoperability and a transition path to const generics. -#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +#[derive(Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] #[repr(transparent)] pub struct Array(pub U::ArrayType); @@ -170,6 +170,24 @@ where } } +impl Clone for Array +where + T: Clone, + U: ArraySize, +{ + fn clone(&self) -> Self { + Self(U::ArrayType::::from_fn(|n| self.0.as_ref()[n].clone())) + } +} + +impl Copy for Array +where + T: Copy, + U: ArraySize, + U::ArrayType: Copy, +{ +} + impl Default for Array where T: Default,