repr_c_wrapper 0.1.1

Opaque `#[repr(C)]` wrapper that can be passed by value over FFI
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented0 out of 3 items with examples
  • Size
  • Source code size: 7.3 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.45 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • luketpeterson/repr_c_wrapper
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • luketpeterson

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.