Struct deno_libffi::middle::Cif[][src]

pub struct Cif { /* fields omitted */ }
Expand description

Describes the calling convention and types for calling a function.

This is the middle layer’s wrapping of the low and raw layers’ ffi_cif. An initialized CIF contains references to an array of argument types and a result type, each of which may be allocated on the heap. Cif manages the memory of those referenced objects.

Construct with Cif::new or Cif::from_type_array.

Examples

extern "C" fn add(x: f64, y: &f64) -> f64 {
    return x + y;
}

use deno_libffi::middle::*;

let args = vec![Type::f64(), Type::pointer()];
let cif = Cif::new(args.into_iter(), Type::f64());

let n = unsafe { cif.call(CodePtr(add as *mut _), &[arg(&5f64), arg(&&6f64)]) };
assert_eq!(11f64, n);

Implementations

Creates a new CIF for the given argument and result types.

Takes ownership of the argument and result Types, because the resulting Cif retains references to them. Defaults to the platform’s default calling convention; this can be adjusted using set_abi.

Calls a function with the given arguments.

In particular, this method invokes function fun passing it arguments args, and returns the result.

Safety

There is no checking that the calling convention and types in the Cif match the actual calling convention and types of fun, nor that they match the types of args.

Sets the CIF to use the given calling convention.

Gets a raw pointer to the underlying ffi_cif.

This can be used for passing a middle::Cif to functions from the low and raw modules.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.