Created
October 31, 2018 12:28
-
-
Save Antti/96877ceb47b4a8ccac4146773fbcbb03 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
unsafe fn transmute_vec<T, U>(vec: Vec<T>) -> Vec<U> { | |
use std::mem; | |
let ratio = mem::size_of::<T>() / mem::size_of::<U>(); | |
let length = vec.len() * ratio; | |
let capacity = vec.capacity() * ratio; | |
let ptr = vec.as_ptr(); | |
mem::forget(vec); | |
Vec::from_raw_parts(ptr as *mut U, length, capacity) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment