pub unsafe fn transmute_vec<T, U>(vector: Vec<T>) -> Vec<U>
Available on crate feature alloc only.
Expand description

Transmutes a Vec<T> into a Vec<U>

Safety

This function has the safety requirements of std::mem::transmute regarding transmuting from T to U. T must also have the same alignment as U.

Example

use core_extensions::utils::transmute_vec;

use std::mem::ManuallyDrop;

unsafe{
    assert_eq!(transmute_vec::<u32, i32>(vec![!0, 0, 1]), vec![-1, 0, 1]);
}

fn make(s: &str) -> ManuallyDrop<String> {
    ManuallyDrop::new(String::from(s))
}
unsafe{
    assert_eq!(
        transmute_vec::<String, ManuallyDrop<String>>(vec!["hello".into(), "world".into()]),
        vec![make("hello"), make("world")],
    );
}