#[repr(C)]pub struct ffi_type {
pub size: usize,
pub alignment: c_ushort,
pub type_: c_ushort,
pub elements: *mut *mut ffi_type,
}Expand description
A struct used by libffi to describe types and their memory layout.
New ffi_type variables should only be constructed for describing the
layout of custom structs. For plain scalar types it is recommended to refer
to the static variables defined by libffi instead of creating new
ffi_types.
When creating new ffi_types, the size and alignment fields should be
left at their default values, as libffi will fill out these fields during
ffi_prep_cif.
§Example
use std::ptr;
#[repr(C)]
struct CustomStruct {
num: u32,
num2: i64,
float_num: f32,
}
// We need to describe the types of the values in `CustomStruct`. The order
// must be the same as the order in the struct definition. Note that this
// array must be alive and at the same address for the entire lifetime of
// the resulting `ffi_type`.
let mut elements_array = unsafe {[
// `libffi::low::types::uint32`, `sint64`, and `float` can be used
// instead if using libffi (not -sys)
ptr::addr_of_mut!(libffi_sys::ffi_type_uint32),
ptr::addr_of_mut!(libffi_sys::ffi_type_sint64),
ptr::addr_of_mut!(libffi_sys::ffi_type_float),
// The last element in the array must be a `NULL` since `ffi_type` does
// not store the number of elements in the struct.
ptr::null_mut(),
]};
let mut custom_struct_description = libffi_sys::ffi_type {
// `libffi::low::type_tag::STRUCT` can be used instead if using libffi
type_: libffi_sys::FFI_TYPE_STRUCT,
elements: elements_array.as_mut_ptr(),
..Default::default()
};
// `custom_struct_description` can now be used in a [`ffi_cif`] to send
// `CustomStruct` as an argument or receive a `CustomStruct` as response.Fields§
§size: usize§alignment: c_ushort§type_: c_ushort§elements: *mut *mut ffi_typeTrait Implementations§
Auto Trait Implementations§
impl Freeze for ffi_type
impl RefUnwindSafe for ffi_type
impl !Send for ffi_type
impl !Sync for ffi_type
impl Unpin for ffi_type
impl UnwindSafe for ffi_type
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more