1 /// @brief 由bindgen生成的结构体转换成rust原生定义的结构体的特性
2 pub trait FFIBind2Rust<T> {
3 /// 转换为不可变引用
convert_ref(src: *const T) -> Option<&'static Self>4 fn convert_ref(src: *const T) -> Option<&'static Self>;
5 /// 转换为可变引用
convert_mut(src: *mut T) -> Option<&'static mut Self>6 fn convert_mut(src: *mut T) -> Option<&'static mut Self>;
7 }
8
__convert_mut<'a, S, D>(src: *mut S) -> Option<&'a mut D>9 pub fn __convert_mut<'a, S, D>(src: *mut S) -> Option<&'a mut D> {
10 return unsafe { core::mem::transmute::<*mut S, *mut D>(src).as_mut() };
11 }
12
__convert_ref<'a, S, D>(src: *const S) -> Option<&'a D>13 pub fn __convert_ref<'a, S, D>(src: *const S) -> Option<&'a D> {
14 return unsafe { core::mem::transmute::<*const S, *const D>(src).as_ref() };
15 }
16