use crate::{private, ReprC, ReprRust};
impl<T, const N: usize> ReprRust<*const T> for &[T; N]
where
*const T: private::CFFISafe,
{
#[inline]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
fn from(ptr: *const T) -> Self {
let s = unsafe { std::slice::from_raw_parts(ptr, N) };
s.try_into().unwrap_or_else(|_| {
let ty = std::any::type_name::<T>();
panic!("impossible to convert &[{ty}] into &[{ty}; {N}]");
})
}
}
impl<T> ReprC<Vec<T>> for *const T
where
*const T: private::CFFISafe,
{
#[inline]
fn from(v: Vec<T>) -> Self {
let x = v.as_ptr();
std::mem::forget(v);
x
}
}
#[test]
fn _1() {
let x = &[1, 2, 3]; let y: &[i32; 3] = ReprRust::from(ReprC::from(x.to_vec()));
assert!(x == y);
}