Created
November 17, 2017 16:51
-
-
Save fizyk20/e0c541bf63d56cc8b343e9961c824242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Consumes a generic array, splitting it at a given position. | |
pub fn split<M: ArrayLength<T>>(self) -> (GenericArray<T, M>, GenericArray<T, Diff<N, M>>) | |
where | |
N: Sub<M>, | |
Diff<N, M>: ArrayLength<T>, | |
{ | |
unsafe { | |
let array_ptr = &self as *const GenericArray<T, N>; | |
let ptr1 = mem::transmute::<_, *const GenericArray<T, M>>(array_ptr); | |
let tmp = mem::transmute::<_, *const T>(array_ptr); | |
let ptr2 = mem::transmute::<_, *const GenericArray<T, Diff<N, M>>>( | |
tmp.offset(M::to_usize() as isize), | |
); | |
(ptr::read(ptr1), ptr::read(ptr2)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment