Expand description
Closures with a #[repr(C)]
layout (inlined vtable),
up to 9 function arguments.
Simplified for lighter documentation, but the actual struct
definitions
and impls range up to ...DynFn...9
.
Examples
FFI-safe Box<dyn FnMut()>
-
use ::safer_ffi::prelude::*; let mut captured = String::from("…"); let ffi_safe: repr_c::Box<dyn Send + FnMut()> = Box::new(move || { captured.push('!'); println!("{}", captured); }) .into() ; fn assert_ffi_safe (_: &impl ReprC) {} assert_ffi_safe(&ffi_safe);
FFI-safe Arc<dyn Fn()>
-
use ::{ safer_ffi::{ prelude::*, }, std::{ sync::Arc, }, }; let captured = String::from("…"); let ffi_safe: repr_c::Arc<dyn Send + Sync + Fn()> = Arc::new(move || { println!("{}", captured); }) .into() ; fn assert_ffi_safe (_: &impl ReprC) {} assert_ffi_safe(&ffi_safe);
Re-exports
pub use self::arc::ArcDynFn0;
pub use self::arc::ArcDynFn1;
pub use self::boxed::BoxDynFnMut0;
pub use self::boxed::BoxDynFnMut1;
pub use borrowed::RefDynFnMut0;
pub use borrowed::RefDynFnMut1;
Modules
- arc
alloc
Arc<dyn 'static + Send + Sync + Fn(...) -> _>
but with a#[repr(C)]
layout (inlined virtual method table). &'lt mut (dyn 'lt + Send + FnMut(...) -> _>
but with a#[repr(C)]
layout (env ptr + function ptr).- boxed
alloc
Box<dyn 'static + Send + FnMut(...) -> _>
but with a#[repr(C)]
layout (inlined virtual method table).