Attribute Macro interoptopus::ffi_function [−][src]
#[ffi_function]
This is supported on crate feature
derive
only.Expand description
Enable an extern "C"
function to appear in generated bindings.
This will derive FunctionInfo
for a helper struct
of the same name containing the function’s name, parameters and return value.
The following attributes can be provided:
Attribute | Explanation |
---|---|
surrogates(x="y") | Invoke function y to provide a CTypeInfo for parameter x , see below. ⚠️ |
debug | Print generated helper code in console. |
unsafe | Unlocks unsafe options marked: ⚠️ |
⚠️ This attribute can lead to undefined behavior when misapplied. When using surrogates you must ensure the surrogate matches the parameter’s type.
Surrogates
When dealing with types outside of your control you will not be able to implement CTypeInfo
for them.
Instead you need a surrogate, a helper function which returns that info for the type.
The surrogate’s signature is:
fn some_foreign_type() -> CType { // Return an appropriate CType }
Example
use interoptopus::ffi_function; #[ffi_function] #[no_mangle] pub extern "C" fn my_function(x: u32) -> u32 { x }