ffi-and-language-interop

Solid

FFI and native interop rules: single documented pointer ownership, opaque handles, null-pointer checks, allocate/free pairs, unsafe-block invariants, generated C headers, stable C ABI, frozen struct layouts, and error/context conversion. Load when writing or reviewing FFI boundaries between native and host languages.

Data & Documents 137 stars 13 forks Updated today MIT

Install

View on GitHub

Quality Score: 84/100

Stars 20%
71
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
53
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

- Every pointer has one owner, documented with `SAFETY` comments or host-language ownership docs. - Use opaque handles across native boundaries. Do not expose Rust, C++, or host-runtime internals directly. - Check all nullable pointers before use and return explicit errors for invalid handles or null inputs. - Provide allocate/free pairs for every caller-owned allocation and document which side frees each value. - Every unsafe block must state the invariant, why it holds, and what would make it invalid. - Generate C headers or native declarations from source when possible, and make CI verify generated files are current. - Treat the C ABI or equivalent native ABI as the stable contract for downstream bindings. - Freeze native struct layouts across compatible releases, and version breaking ABI changes deliberately. - Convert native errors to host exceptions, result objects, or idiomatic error values at every boundary. - Preserve diagnostic context across boundaries: message, numeric code when available, source operation, and cause chain.

Details

Author
Goldziher
Repository
Goldziher/ai-rulez
Created
1 years ago
Last Updated
today
Language
Go
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Listed

rust-ffi

Design an FFI boundary meant to last — a thin translation layer with the logic in core crates, no panic across the boundary, explicit ownership on every pointer, repr(transparent) newtypes, and unsafe extern in edition 2024. Use when designing or reviewing a Rust FFI surface, when exposing a Rust library to another language, when a DLL or shared library keeps state, or when the user asks how to shape an extern function.

1 Updated 4 days ago
rewrite-rs
Data & Documents Listed

uniffi-boundary

Use when you author, change, or review a UniFFI cross-language boundary crate that generates Kotlin and Swift bindings from Rust. Covers proc-macro-first scaffolding versus UDL, the Record/Object/Enum/Error derives, the Record-versus-Object decision, Send + Sync requirements on exported interfaces, Arc-based ownership and object identity across the boundary, callback interfaces and foreign traits, custom types and newtype converters, versioned payloads that cross as JSON strings, coarse-boundary and large-data rules, built-in type mapping to Kotlin and Swift, async export rules, codegen failure triage, and a review checklist. Triggers on uniffi, uniffi::export, uniffi::constructor, derive Record/Object/Enum/Error, setup_scaffolding, uniffi-bindgen, UDL, callback_interface, with_foreign, custom_newtype, foreign trait, or any question about what may cross an FFI boundary.

0 Updated today
po4yka
Web & Frontend Listed

ffi-error-progress-cancel

Use when you design or review an FFI boundary for a long-running Rust operation that must report typed errors, stream progress, and cancel cooperatively - import, indexing, preview, render, export, or any job longer than one frame. Covers a closed versioned boundary error taxonomy, UniFFI flat error enums, mapping stable error codes to native UX buckets, redaction so no backtrace or filesystem path crosses the boundary, callback-interface progress listeners carrying job id plus stage and fraction, bridges to Kotlin Flow with callbackFlow and awaitClose and to Swift AsyncThrowingStream with onTermination, and wiring coroutine cancel and Task cancel down to an idempotent non-blocking cancel_job. Triggers on flat_error, callback interface, callbackFlow, awaitClose, trySend, AsyncThrowingStream, CancellationException, CancellationError, cancel_job, job_id, progress event, or "the UI must not show stack traces".

0 Updated today
po4yka