Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Designs and reviews Rust FFI boundaries, isolating unsafe extern declarations behind safe ownership, error, and cleanup wrappers.
88% 96%+8 ptsof test cases passed
Passed 24 of 25 test cases with the skill, and 22 of 25 without it.
I have C header signatures for a graphics library that creates a context pointer, accepts configuration string parameters, and requires explicit destruction. Could you write a safe Rust wrapper module around these foreign function declarations? I need an idiomatic Rust interface that manages the handle lifetime, converts return error codes into standard Rust Results, and bridges string types safely.
Uses `unsafe extern "C"` blocks for foreign function declarations.
3 of 3 safety checks passed
Use this skill to wrap foreign interfaces in Rust APIs that make ownership, lifetimes, errors, and cleanup explicit. FFI code should be unsafe at the raw boundary and safe for normal Rust callers.
unsafe extern
bindings in a small private module.unsafe extern "C" blocks for modern Rust, especially Rust 2024 edition
code. Leave safety-conditional items unqualified or explicitly unsafe, and
mark individual extern items safe only when calling them is safe for all
Rust inputs.#[repr(C)] for structs and enums that cross the ABI boundary. Do not
expose Rust-only layout types across C.CString for owned nul-terminated strings sent to C and CStr for
borrowed C strings. Never treat arbitrary C memory as Rust-owned.Drop cleanup using
the matching foreign deallocator.extern "C" boundaries. Catch panics or
expose an ABI that permits unwinding only when deliberately using
"C-unwind".Read references/ffi-boundary-patterns.md before adding or reviewing FFI
bindings.
core::ffi or std::ffi C types over guessing integer sizes.Result at the wrapper boundary.Option<NonNull<T>> internally when useful,
but expose safe Rust types to callers.PhantomData when the compiler cannot see the relationship.OnceLock, LazyLock, or
Once when the foreign library requires process-wide setup.bindgen for large or changing C headers and cbindgen when exporting aNext to this one in the catalogue, plus more from the same author.