6 releases

new 0.0.7 May 13, 2024
0.0.6 Apr 4, 2024
0.0.5 Mar 8, 2024
0.0.4 Jan 12, 2024

#103 in FFI

Download history 4/week @ 2024-01-20 36/week @ 2024-02-03 9/week @ 2024-02-17 4/week @ 2024-02-24 136/week @ 2024-03-02 59/week @ 2024-03-09 4/week @ 2024-03-16 29/week @ 2024-03-23 163/week @ 2024-03-30 66/week @ 2024-04-06 54/week @ 2024-04-13 9/week @ 2024-04-20 6/week @ 2024-04-27 33/week @ 2024-05-04

135 downloads per month

BSD-2-Clause

30KB
783 lines

ffi_types

This repository provides C-ABI compatible basic Rust types including box, slice, str and boxed slice/str. By carefully following instructions, the types are bindgen/cbindgen compatible and owned values are safe under C++.

The project consists of 2 parts. A rust crate of #[repr(C)] wrappers of rust types and a header file for C++ (or a few more later).

The conversions are intended to be zero-cost.

TODO: link to docs and examples

CBindgen

Use ffi_types::cbindgen::with_cxx_ffi_types() to add proper configuration to cbindgen::Builder.

Bindgen

Block the provided header to blocklist_file. Replace all root::ffi_types:: to ffi_types:: in generated file.

Not the best choice for FFI

If you start a new project, please check cxx fits in your case.

Since the goal of ffi_types is exposing Rust type to C++ side, you need access to C++ code base.

ffi_types only provides types. Nothing is automatic. You still need to manage bindgen/cbindgen.

MSVC is very picky. ffi_types limits convenience initializers for C-prefixed types for MSVC. It will be less convenient and more unsafe.

Dependencies

~0–9MB
~85K SLoC