docs.rs failed to build closure-ffi-0.1.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
closure-ffi-5.0.1
Provides wrappers around closures which allows them to be called through context-free unsafe bare functions.
Context-free bare functions are not needed very often, as properly designed C APIs typically allow the user to specify an opaque pointer to a context object which will be provided to the function pointer. However, this is not always the case, and may be impossible in less common scenarios, e.g. function hooking for game modding/hacking.
Features
The crate comes with the following feature flags:
no_std: Makes the crate compatible with#![no_std]. A dependency onallocandspinis still required.bundled_jit_alloc: Provides a global JIT allocator through thejit-allocatorcrate. This is enabled by default.hrtb_macro: Provides the [cc::hrtb] proc macro which is necessary for creating bare functions with signatures that involve higher-kinded lifetimes (i.e.for<'a, ...>statements).full: Enables all features except forno_std.
Examples
Passing a closure to a C API taking a contextless function pointer:
use ;
// Imagine we have an foerign C API for reigstering and unregistering some callback function.
// Notably, the API does not let the user provide a context object to the callback.
unsafe extern "C"
unsafe extern "C"
// We want to keep track of sum of callback arguments without using statics. This is where
// closure-ffi comes in:
let mut sum = 0;
let wrapped = new;
// Safety: Here, we assert that the foreign API won't use the callback
// in ways that break Rust's safety rules. Namely:
// - The exclusivity of the FnMut's borrow is respected.
// - If the calls are made from a different thread, the closure is Sync.
// - We unregister the callback before the BareFnMut is dropped.
unsafe