Special Type Conversion
GuiyinLi opened this issue · comments
How to convert types similar to Result<usize>
and Option<Arc<SpinLock<my_type>>>
into types in the C language, where my_type
is a struct defined in another Rust file(Conversion of Nested Types).
Meanwhile, for C
structs used in Rust through bindings
, can they be directly used as the original C
structs in the C
language? For example, filp: *mut bindings::file
, can I directly use struct file
in C
language to replace it?"
In addition, I would like to know if cbindgen
can convert the structs from all Rust files in a project into C language (with mutual dependencies between the structs), because currently I can only convert a single Rust file.
You need to box them or use enums that have #[repr(C)]
or #[repr(u8)]
. Or treat them as opaque and only pass them by pointer (but that's not usable for return types for obvious reasons).
I would like to know if cbindgen can convert the structs from all Rust files in a project into C language (with mutual dependencies between the structs), because currently I can only convert a single Rust file.
It definitely can. If you point it to a lib.rs it should generate all dependent modules. Also if you want dependencies generated there are options for that (parse_deps
, in particular).