From ce4702c7b69f7e76ea509e5fd8d7f51e7432ff37 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 8efeae7..1e13a60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,6 +215,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];