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