1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#![cfg_attr(rustfmt, rustfmt::skip)]
//! 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()>`
//!
/*! - ```rust
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()>`
//!
/*! - ```rust
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);
``` */
//!
cfg_alloc! {
pub mod arc;
pub mod boxed;
#[doc(no_inline)]
pub use self::{
arc::{ArcDynFn0, ArcDynFn1},
boxed::{BoxDynFnMut0, BoxDynFnMut1},
};
#[cfg(not(docs))]
#[doc(no_inline)]
pub use self::{
arc::{
ArcDynFn2, ArcDynFn3, ArcDynFn4, ArcDynFn5,
ArcDynFn6, ArcDynFn7, ArcDynFn8, ArcDynFn9,
},
boxed::{
BoxDynFnMut2, BoxDynFnMut3, BoxDynFnMut4, BoxDynFnMut5,
BoxDynFnMut6, BoxDynFnMut7, BoxDynFnMut8, BoxDynFnMut9,
},
};
}
pub mod borrowed;
#[doc(no_inline)]
pub use borrowed::{RefDynFnMut0, RefDynFnMut1};
#[cfg(not(docs))]
#[doc(no_inline)]
pub use borrowed::{
RefDynFnMut2, RefDynFnMut3, RefDynFnMut4, RefDynFnMut5,
RefDynFnMut6, RefDynFnMut7, RefDynFnMut8, RefDynFnMut9,
};