ffi-convert
Convert between idiomatic Rust values and C-compatible data structures with a minimum of unsafe ceremony.
ffi-convert provides two conversion traits — CReprOf (Rust → C) and
AsRust (C → Rust) — plus CDrop and RawPointerConverter to handle
ownership of pointer fields, and derive macros that take care of the
boilerplate.
use ;
use ;
let pizza = Pizza ;
let c_pizza = c_repr_of.unwrap; // Rust -> C
let again: Pizza = c_pizza.as_rust.unwrap; // C -> Rust
Workspace layout
| Crate | What's in it |
|---|---|
ffi-convert |
The conversion traits (CReprOf, AsRust, CDrop, RawPointerConverter, RawBorrow). |
ffi-convert-derive |
#[derive(...)] macros for all four conversion traits. Re-exported from ffi-convert. |
ffi-convert-extra-ctypes |
Optional C-compatible containers: CArray<T> (Vec<U>), CStringArray (Vec<String>), CRange<T>. |
ffi-convert-tests |
Workspace tests, including C round-trip tests with AddressSanitizer / MemorySanitizer. |
Full documentation lives on docs.rs/ffi-convert, including the type-mapping table, attribute reference, and caveats that apply to the derives.
More on open source projects at Sonos here.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.