From c07306e2aeef653bee737d9d4cdd8dfc94bd679a Mon Sep 17 00:00:00 2001 From: Leonora Tindall Date: Sun, 7 Nov 2021 12:54:13 -0600 Subject: [PATCH] feat: add Into<> impls for ExactSlice and MinSlice --- src/lib.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 2587af5..ef1b910 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -229,6 +229,30 @@ impl ExactSlice { } } +impl<'a, T, const N: usize> Into<&'a MinSlice> for &'a ExactSlice { + fn into(self) -> &'a MinSlice { + self.as_min_slice() + } +} + +impl<'a, T, const N: usize> Into<&'a mut MinSlice> for &'a mut ExactSlice { + fn into(self) -> &'a mut MinSlice { + self.as_mut_min_slice() + } +} + +impl<'a, T, const N: usize> Into<&'a ExactSlice> for &'a MinSlice { + fn into(self) -> &'a ExactSlice { + unsafe { ExactSlice::from_slice_unchecked(&self.head[..]) } + } +} + +impl<'a, T, const N: usize> Into<&'a mut ExactSlice> for &'a mut MinSlice { + fn into(self) -> &'a mut ExactSlice { + unsafe { ExactSlice::from_mut_unchecked(&mut self.head[..]) } + } +} + #[test] fn basic_min_success() { let slice = &[1, 2, 3, 4, 5, 6];