1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
pub use libc::{
    c_char,
    c_float,
    c_int,
    c_long,
    c_longlong,
    c_short,
    c_size_t,
    c_ssize_t,
    c_uchar,
    c_uint,
    c_uintptr_t,
    c_ulong,
    c_ushort,
    c_void,
};

use core::fmt::{Debug, Formatter, Result};
use core::marker::PhantomData;
use core::slice;

#[repr(C)]
#[derive(Default)]
pub struct FAM<T>(PhantomData<T>, [T; 0]);
impl<T> FAM<T> {
    #[inline]
    pub const fn new() -> Self {
        FAM(PhantomData, [])
    }
    #[inline]
    pub fn as_ptr(&self) -> *const T {
        self as *const _ as *const T
    }
    #[inline]
    pub fn as_mut_ptr(&mut self) -> *mut T {
        self as *mut _ as *mut T
    }
    #[inline]
    pub unsafe fn as_slice(&self, len: usize) -> &[T] {
        slice::from_raw_parts(self.as_ptr(), len)
    }
    #[inline]
    pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
        slice::from_raw_parts_mut(self.as_mut_ptr(), len)
    }
}

impl<T> Debug for FAM<T> {
    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
        fmt.write_str("FAM")
    }
}