askill
binding-crate-architecture-patterns

binding-crate-architecture-patternsSafety 85Repository

Instructions for binding crate architecture patterns.

558 stars
11.2k downloads
Updated 3/7/2026

Package Files

Loading files...
SKILL.md

priority: high

Binding Crate Architecture Patterns

Principles

  1. Minimal wrapper: Bindings are glue only — call Rust core, convert types, convert errors
  2. Type translation: Clear Rust ↔ host language mapping
  3. Error conversion: Rust errors → native exceptions/error types
  4. Memory safety: Respect language-specific ownership models
  5. Testing: Language-native test suite, not just Rust tests

Crate Naming

{lib}-{language}: -py (PyO3), -node (NAPI-RS), -rb (Magnus), -php (ext-php-rs), -wasm (wasm-bindgen), -ffi (C FFI for Go/Java/C#)

Framework Patterns

FrameworkMacroConstructorError Pattern
PyO3#[pyclass] / #[pymethods]#[new].map_err(|e| PyException::new_err(e.to_string()))
NAPI-RS#[napi]#[napi(constructor)]napi::Error::new(Status::GenericFailure, msg)
Magnus#[magnus::wrap]define_method("new", ...)Into<magnus::RError>
ext-php-rs#[php_class] / #[php_impl]pub fn new()Return error string
wasm-bindgen#[wasm_bindgen]#[wasm_bindgen(constructor)]JsValue::from_str(&e.to_string())
C FFI#[no_mangle] extern "C"_new() -> HandleReturn null + error code

Type Mapping

RustPythonNode.jsRubyC/FFI
String/&strstrstringStringchar*/const char*
u64intBigIntIntegeruint64_t
Result<T>ExceptionError thrownraisesnull/error code
Option<T>None/Tnull/Tnil/TNULL/T

Distribution (packages/)

python/ (PyPI), typescript/ (npm), ruby/ (RubyGems), php/ (Composer), go/ (Go module), java/ (Maven), csharp/ (.NET NuGet)

Anti-Patterns

  • Exposing Rust internals to users
  • Blocking in async contexts (use spawn_blocking)
  • Dangling pointers in FFI returns
  • Panicking instead of returning errors (unwrap() in binding code)

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

75/100Analyzed 3/8/2026

High-density technical reference for Rust binding crate architecture patterns. Well-structured with comprehensive tables covering framework patterns, type mappings, and anti-patterns. Scores well on clarity, safety, and reusability but lacks actionable step-by-step instructions. The .codex path suggests internal agent config, though content is generic enough for broader use. Missing trigger section reduces completeness slightly.

85
85
80
70
50

Metadata

Licenseunknown
Version-
Updated3/7/2026
Publisherkreuzberg-dev

Tags

testing