]> git.nega.tv - josh/narcissus/commitdiff
Add Clone impl to FixedVec
authorJoshua Simmons <josh@nega.tv>
Sat, 18 Feb 2023 13:22:35 +0000 (14:22 +0100)
committerJoshua Simmons <josh@nega.tv>
Sat, 18 Feb 2023 13:22:35 +0000 (14:22 +0100)
narcissus-core/src/fixed_vec.rs

index d76fcd672afb2955b5807ac1ee1a3ba4a4ddf571..3fb12e5b9e9a65397123cdef9e24c7e9763b455d 100644 (file)
@@ -108,9 +108,7 @@ impl<T, const CAP: usize> FixedVec<T, CAP> {
         #[cold]
         #[inline(never)]
         fn assert_failed(index: usize, len: usize) -> ! {
-            panic!(
-                "swap_remove index (is {index}) should be < len (is {len})"
-            );
+            panic!("swap_remove index (is {index}) should be < len (is {len})");
         }
 
         let len = self.len();
@@ -133,9 +131,7 @@ impl<T, const CAP: usize> FixedVec<T, CAP> {
         #[cold]
         #[inline(never)]
         fn assert_failed(index: usize, len: usize) -> ! {
-            panic!(
-                "insertion index (is {index}) should be <= len (is {len})"
-            );
+            panic!("insertion index (is {index}) should be <= len (is {len})");
         }
 
         let len = self.len();
@@ -495,6 +491,19 @@ impl<T: Clone, const CAP: usize> FixedVec<T, CAP> {
     }
 }
 
+impl<T, const CAP: usize> Clone for FixedVec<T, CAP>
+where
+    T: Clone,
+{
+    fn clone(&self) -> Self {
+        let mut v = Self::new();
+        for i in self {
+            v.push(i.clone())
+        }
+        v
+    }
+}
+
 impl<T: PartialEq, const CAP: usize> FixedVec<T, CAP> {
     #[inline]
     pub fn dedup(&mut self) {