feat: add Into<> impls for ExactSlice and MinSlice

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

View File

@ -215,6 +215,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];