Skip to content

Commit 0726442

Browse files
authored
hybrid-array: looser Clone and Copy bounds on Array (#939)
Switches from derived impls of `Clone` and `Copy` to handwritten ones which use the minimal required bounds for the underlying types.
1 parent 1a917fa commit 0726442

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

hybrid-array/src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use typenum::Unsigned;
3838
///
3939
/// Provides the flexibility of typenum-based expressions while also
4040
/// allowing interoperability and a transition path to const generics.
41-
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
41+
#[derive(Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
4242
#[repr(transparent)]
4343
pub struct Array<T, U: ArraySize>(pub U::ArrayType<T>);
4444

@@ -170,6 +170,24 @@ where
170170
}
171171
}
172172

173+
impl<T, U> Clone for Array<T, U>
174+
where
175+
T: Clone,
176+
U: ArraySize,
177+
{
178+
fn clone(&self) -> Self {
179+
Self(U::ArrayType::<T>::from_fn(|n| self.0.as_ref()[n].clone()))
180+
}
181+
}
182+
183+
impl<T, U> Copy for Array<T, U>
184+
where
185+
T: Copy,
186+
U: ArraySize,
187+
U::ArrayType<T>: Copy,
188+
{
189+
}
190+
173191
impl<T, U> Default for Array<T, U>
174192
where
175193
T: Default,

0 commit comments

Comments
 (0)