Module demes::ffi

source ·
Expand description

Define a foreign function interface (FFI) for this crate.

The FFI allows demes to be used by any language compatible with the C calling convention.

We recommend cbindgen to generate a C or C++ header file from this module.

We suggest corrosion for building using cmake.

It should be possible to use other build systems such as meson. However, we have not experimented with this. We will update this section if and when we do so.

See the c_example folder in the demes folder of this crate’s repository for a fully worked out example.

§Notes

The rust API stores all strings as String, which is very different from the C pointer to std::ffi::c_char. Therefore, most functions returning * c_char return a copy of the data stored by rust. It is up to the client code to free these returned data.

Functions returning pointers all document if the return value must be freed and, if so, how to do so.

Many of the function in this module do not have an unsafe label. These labels are correct. When called from rust, these functions are indeed safe. The borrow checker prevents them from being unsafe.

However, when called from languages like C, this API is subject to the same safety pitfalls as any API for that language. Witout rust’s borrow checker, it is up to client code to make sure that parent objects (Graphs for example) are still valid when child objects (Demes for example) are passed to API functions.

Structs§

Enums§

Functions§