From 22935fccc62e4de81ab1b7f5178e7fced3b0d574 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 24 May 2021 14:25:13 -0700 Subject: [PATCH] Use const generics for IntoRefs Yay! Now we can use an array of any size, slice, or vector. --- piet-gpu-hal/src/hub.rs | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/piet-gpu-hal/src/hub.rs b/piet-gpu-hal/src/hub.rs index 116939c..2ad9651 100644 --- a/piet-gpu-hal/src/hub.rs +++ b/piet-gpu-hal/src/hub.rs @@ -502,43 +502,7 @@ impl<'a, T> IntoRefs<'a, T> for &'a [&'a T] { } } -// TODO: this will benefit from const generics! -impl<'a, T> IntoRefs<'a, T> for &'a [&'a T; 1] { - type Iterator = std::iter::Copied>; - fn into_refs(self) -> Self::Iterator { - self.into_iter().copied() - } -} - -impl<'a, T> IntoRefs<'a, T> for &'a [&'a T; 2] { - type Iterator = std::iter::Copied>; - fn into_refs(self) -> Self::Iterator { - self.into_iter().copied() - } -} - -impl<'a, T> IntoRefs<'a, T> for &'a [&'a T; 3] { - type Iterator = std::iter::Copied>; - fn into_refs(self) -> Self::Iterator { - self.into_iter().copied() - } -} - -impl<'a, T> IntoRefs<'a, T> for &'a [&'a T; 4] { - type Iterator = std::iter::Copied>; - fn into_refs(self) -> Self::Iterator { - self.into_iter().copied() - } -} - -impl<'a, T> IntoRefs<'a, T> for &'a [&'a T; 5] { - type Iterator = std::iter::Copied>; - fn into_refs(self) -> Self::Iterator { - self.into_iter().copied() - } -} - -impl<'a, T> IntoRefs<'a, T> for &'a [&'a T; 6] { +impl<'a, T, const N: usize> IntoRefs<'a, T> for &'a [&'a T; N] { type Iterator = std::iter::Copied>; fn into_refs(self) -> Self::Iterator { self.into_iter().copied()