drm/
util.rs

1//! Utilities used internally by this crate.
2
3use crate::control::{from_u32, RawResourceHandle};
4
5pub unsafe fn transmute_vec<T, U>(from: Vec<T>) -> Vec<U> {
6    let mut from = std::mem::ManuallyDrop::new(from);
7
8    Vec::from_raw_parts(from.as_mut_ptr() as *mut U, from.len(), from.capacity())
9}
10
11pub unsafe fn transmute_vec_from_u32<T: From<RawResourceHandle>>(raw: Vec<u32>) -> Vec<T> {
12    if cfg!(debug_assertions) {
13        raw.into_iter()
14            .map(|handle| from_u32(handle).unwrap())
15            .collect()
16    } else {
17        transmute_vec(raw)
18    }
19}