use crate::{private, repr_hs_ptr, HsType, ReprC, ReprHs, 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 {
unsafe {
let x = std::slice::from_raw_parts(ptr, N);
std::mem::transmute_copy::<&[T], &[T; N]>(&x)
}
}
}
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
}
}
repr_hs_ptr!(&[T]);
repr_hs_ptr!(Vec<T>);
#[test]
fn _1() {
let x = &[1, 2, 3]; let y: &[i32; 3] = ReprRust::from(ReprC::from(x.to_vec()));
assert!(x == y);
}