🦀🚀 Abstract over `Send` and `!Send` traits crates.io/crates/future_form
README.md

Simple Counter #

A minimal FFI example demonstrating future_form's host-driven polling pattern. A counter service exposes async methods that foreign hosts (Go, Java, Python) drive to completion via poll_once().

What this demonstrates #

  • Writing a trait generic over FutureForm (Counter<K>)
  • Generating concrete impls with #[future_form(Sendable)]
  • Wrapping a BoxFuture in a HostHandle for C ABI export
  • The same trait impl serving both tokio .await and FFI poll_once()

Structure #

counter_simple/
├── counter/        Domain logic: Counter<K> trait + SimpleCounter
├── rust_bridge/    C ABI + JNI bridge
├── tokio_host/     Rust host using tokio (same trait impl)
├── go_host/        Go host via CGo
├── java_host/      Java host via JNI
├── python_host/    Python host via ctypes
└── run_test.sh     Build + run across all hosts

Running #

From the workspace root, using nix develop .#ffi for foreign toolchains:

./future_form_ffi/examples/counter_simple/run_test.sh

Or run individual hosts:

# Tokio (no extra toolchains needed)
cargo run --manifest-path future_form_ffi/examples/counter_simple/tokio_host/Cargo.toml

# Go
cargo build --manifest-path future_form_ffi/examples/counter_simple/rust_bridge/Cargo.toml
cd future_form_ffi/examples/counter_simple/go_host && go run .

Next steps #

For effect handling (host-fulfilled timestamps, logging), see the counter_effects example. For concurrent per-future effect slots, see the key_value_store example.