feat: add Into<> impls for ExactSlice and MinSlice

This commit is contained in:
Leonora Tindall 2021-11-07 12:54:13 -06:00
parent 3349bf2652
commit c07306e2ae
Signed by: nora
GPG Key ID: 7A8B52EC67E09AAF
1 changed files with 24 additions and 0 deletions

View File

@ -229,6 +229,30 @@ impl<T, const N: usize> ExactSlice<T, N> {
}
}
impl<'a, T, const N: usize> Into<&'a MinSlice<T, N>> for &'a ExactSlice<T, N> {
fn into(self) -> &'a MinSlice<T, N> {
self.as_min_slice()
}
}
impl<'a, T, const N: usize> Into<&'a mut MinSlice<T, N>> for &'a mut ExactSlice<T, N> {
fn into(self) -> &'a mut MinSlice<T, N> {
self.as_mut_min_slice()
}
}
impl<'a, T, const N: usize> Into<&'a ExactSlice<T, N>> for &'a MinSlice<T, N> {
fn into(self) -> &'a ExactSlice<T, N> {
unsafe { ExactSlice::from_slice_unchecked(&self.head[..]) }
}
}
impl<'a, T, const N: usize> Into<&'a mut ExactSlice<T, N>> for &'a mut MinSlice<T, N> {
fn into(self) -> &'a mut ExactSlice<T, N> {
unsafe { ExactSlice::from_mut_unchecked(&mut self.head[..]) }
}
}
#[test]
fn basic_min_success() {
let slice = &[1, 2, 3, 4, 5, 6];