repr_c_wrapper

Crates.iorepr_c_wrapper
lib.rsrepr_c_wrapper
version0.1.1
sourcesrc
created_at2023-07-10 22:14:39.319312
updated_at2023-07-11 03:01:37.958359
descriptionOpaque `#[repr(C)]` wrapper that can be passed by value over FFI
homepage
repositoryhttps://github.com/luketpeterson/repr_c_wrapper
max_upload_size
id913329
size7,650
(luketpeterson)

documentation

https://docs.rs/repr_c_wrapper

README

Opaque #[repr(C)] wrapper for #[repr(Rust)] types that can be passed by value over FFI

IMPORTANT Only types requiring 8 Byte alignment or less can be wrapped, and the C environment must align uint64_t to at least 8 Byte boundaries.

use repr_c_wrapper::*;

#[repr(C)]
pub struct OpaqueWrapper(repr_c_wrapper_t!(String));

#[no_mangle]
pub extern "C" fn some_func() -> OpaqueWrapper {
   OpaqueWrapper("hello".to_string().into())
}

Acknowledgment Thanks to @QuineDot, @H2CO3, and @bruecki for identifying unsound practices in earlier drafts of this crate.

Commit count: 4

cargo fmt