Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. use std::convert::TryInto;
  2.  
  3. pub fn convert0(t: &[f32; 4]) -> &[f32; 3] {
  4. t[0..3].try_into().unwrap()
  5. }
  6.  
  7. pub fn convert1(t: &[f32; 4]) -> &[f32; 3] {
  8. t[0..3].try_into().unwrap_or_else(|_| unsafe { std::hint::unreachable_unchecked() })
  9. }
  10.  
  11. pub fn convert2(t: &[f32; 4]) -> &[f32; 3] {
  12. unsafe { std::mem::transmute::<&[f32; 4], &[f32; 3]>(t) }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement