[−][src]Module libffi::low::type_tag
Type tags used in constructing and inspecting ffi_type
s.
For atomic types this tag doesn’t matter because libffi predeclares
an instance of each one. However, for composite
types (structs and complex numbers), we need to create a new
instance of the ffi_type
struct. In particular, the type_
field
contains a value that indicates what kind of type is represented,
and we use these values to indicate that that we are describing a
struct or complex type.
Examples
Suppose we have the following C struct:
struct my_struct {
uint16_t f1;
uint64_t f2;
};
To pass it by value to a C function we can construct an
ffi_type
as follows using type_tag::STRUCT
:
use std::ptr; use libffi::low::{ffi_type, types, type_tag}; let mut elements = unsafe { [ &mut types::uint16, &mut types::uint64, ptr::null_mut::<ffi_type>() ] }; let mut my_struct: ffi_type = Default::default(); my_struct.type_ = type_tag::STRUCT; my_struct.elements = elements.as_mut_ptr();
Constants
STRUCT | Indicates a structure type. |