hsrs
Call Rust from Haskell with type-safe, automatically generated FFI bindings.
Annotate your Rust types and functions, run the code generator, and get idiomatic Haskell that handles memory management, serialization, and type conversions for you.
Quick start
1. Annotate your Rust code
#[hsrs::module] mod canvas { #[hsrs::value_type] pub struct Point { pub x: i32, pub y: i32, } #[hsrs::data_type] pub struct Canvas { points: Vec<Point>, } impl Canvas { #[hsrs::function] pub fn new() -> Self { Self { points: vec![] } } #[hsrs::function] pub fn add_point(&mut self, p: Point) { self.points.push(p); } #[hsrs::function] pub fn count(&self) -> u64 { self.points.len() as u64 } } }
2. Generate Haskell bindings
cargo install hsrs-codegen hsrs-codegen src/lib.rs -o Bindings.hs
3. Use from Haskell
import Bindings main :: IO () main = do c <- new addPoint c (Point 10 20) n <- count c print n -- 1
... continue reading