.cursor/skills/rust-ffi-bindings/SKILL.md
--- name: rust-ffi-bindings description: Guides Rust FFI bindings implementation: FFI bindings, type conversion, memory management, error handling, Flutter Rust Bridge. Use when implementing Rust FFI bindings, native code integration, or FFI callbacks. --- # Rust FFI Bindings ## Core Purpose Rust FFI bindings bridge Rust code with Dart/Flutter using C-compatible FFI. ## Architecture Pattern ``` Dart Code ↓ (C FFI) Rust Wrapper ↓ (creates function pointers) C Library / Dart Callbacks
npx skillsauth add avra-cadavra/avrai .cursor/skills/rust-ffi-bindingsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Rust FFI bindings bridge Rust code with Dart/Flutter using C-compatible FFI.
Dart Code
↓ (C FFI)
Rust Wrapper
↓ (creates function pointers)
C Library / Dart Callbacks
// Rust FFI function (C-compatible)
#[no_mangle]
pub extern "C" fn rust_function_name(
param1: *const c_char,
param2: c_int,
) -> c_int {
// Implementation
// Convert C types to Rust types
// Call Rust code
// Convert Rust result to C type
// Return C-compatible result
}
// Callback registry for Dart callbacks
type CallbackId = u64;
#[repr(C)]
pub struct CallbackArgs {
pub callback_id: u64,
pub arg1: *mut c_void,
pub arg2: *mut c_void,
}
// Global callback registry (thread-safe)
static CALLBACK_REGISTRY: Mutex<CallbackRegistry> = Mutex::new(CallbackRegistry {
dispatch: None,
});
// Register Dart callback
#[no_mangle]
pub extern "C" fn register_dart_callback(callback: DispatchCallback) {
let mut registry = CALLBACK_REGISTRY.lock().unwrap();
registry.dispatch = Some(callback);
}
import 'dart:ffi';
import 'package:ffi/ffi.dart';
// Load Rust library
final DynamicLibrary rustLib = DynamicLibrary.open('libsignal_ffi_wrapper.so');
// Define function signature
typedef RegisterCallbackNative = Void Function(Pointer<Void>);
typedef RegisterCallback = void Function(Pointer<Void>);
// Get function
final registerCallback = rustLib.lookupFunction<
RegisterCallbackNative,
RegisterCallback>('register_dart_callback');
// Register Dart callback
final dispatchCallback = Pointer.fromFunction<DispatchFunctionNative, int>(
dispatchFunction, // Dart function
);
registerCallback(dispatchCallback);
// Rust manages memory for FFI
pub extern "C" fn allocate_buffer(size: usize) -> *mut u8 {
let buffer = vec![0u8; size];
Box::into_raw(buffer.into_boxed_slice()) as *mut u8
}
pub extern "C" fn free_buffer(ptr: *mut u8, size: usize) {
if !ptr.is_null() {
unsafe {
let _ = Box::from_raw(std::slice::from_raw_parts_mut(ptr, size));
}
}
}
// Return error codes from FFI functions
#[no_mangle]
pub extern "C" fn rust_operation() -> c_int {
match perform_operation() {
Ok(_) => 0, // Success
Err(e) => {
// Log error
eprintln!("Error: {}", e);
-1 // Error code
}
}
}
For complex integration, use Flutter Rust Bridge:
// flutter_rust_bridge macro
use flutter_rust_bridge::frb;
#[frb(sync)]
pub fn calculate_compatibility(
profile_a: Vec<f64>,
profile_b: Vec<f64>,
) -> Result<f64, String> {
// Implementation
Ok(compatibility_score)
}
native/signal_ffi/wrapper_rust/src/lib.rs - Rust FFI wrapper examplenative/knot_math/src/api.rs - FFI API examplenative/signal_ffi/wrapper_rust/README.md - FFI setup guidedevelopment
--- name: world-model-development description: Guides world model development patterns: state/action encoders, ONNX inference, feature extraction pipeline, latency budgets. Use when implementing world model components, state encoders, action encoders, feature extractors, or ONNX models. Core skill for Phases 3-6. --- # World Model Development Patterns ## Core Principle All world model components follow LeCun's autonomous machine intelligence framework. State observations flow through a percep
tools
Implements base workflow controller patterns for multi-step processes. Use when creating complex workflows that require orchestration of multiple steps with error handling and rollback.
testing
--- name: widget-test-patterns description: Guides widget test patterns: BLoC testing, user interactions, state changes, material app setup. Use when writing widget tests, testing UI components, or validating widget behavior. --- # Widget Test Patterns ## Core Pattern Widget tests verify UI behavior: user interactions, state changes, and visual display. ## Basic Widget Test Setup ```dart testWidgets('widget displays correctly', (WidgetTester tester) async { // Arrange: Create widget awa
testing
--- name: test-template-generation description: Generates test templates: unit, widget, integration, service tests following project patterns. Use when creating new tests or ensuring tests follow project standards. --- # Test Template Generation ## Available Templates Test templates are located in `test/templates/`: - `unit_test_template.dart` - `widget_test_template.dart` - `integration_test_template.dart` - `service_test_template.dart` ## Unit Test Template ```dart /// SPOTS Component Uni