sans, composable coroutine-based programming
sans is a coroutine combinators library for building composable, resumable computations in Rust. Build pipelines that yield, resume, and compose beautifully.
What are coroutine combinators? Instead of writing complex state machines with explicit state tracking, you compose small, focused functions into pipelines. Each coroutine can yield intermediate results, maintain state, and pass control to the next coroutine. The result is code that's easier to write, test, and reuse - all with compile-time type safety and zero-cost abstractions.
Example
Interactive calculator that maintains state across inputs:
use *;
// Build a stateful calculator that accumulates results
let mut total = 0_i64;
let calculator = init_repeat
.map_input
.map_yield;
// Execute the pipeline
let = calculator.init.unwrap_yielded;
println!; // "total=0"
println!; // "total=5"
println!; // "total=2"
println!; // "total=12"
Chained pipeline with transformation:
use *;
let pipeline = init_once
.map_yield
.chain
.map_return;
let result = handle;
println!; // "Result: 45"
Why sans?
Build stateful, resumable pipelines for:
- Interactive Protocols - REPLs, network protocols, multi-step wizards
- Streaming Pipelines - Data processing, stream transformations, ETL
- State Machines - Protocol implementations, workflow engines, game AI
- Incremental Computation - Pausable async workflows, cooperative multitasking
Key benefits:
- Composable - Build complex pipelines from simple, reusable coroutines
- Type-safe - Compiler ensures coroutines compose correctly
- Zero-cost - No allocations in core combinators, stack-based state machines
- Safe -
#![forbid(unsafe_code)], no manual state management bugs - Concurrent - Run multiple coroutines concurrently with
join
Installation
Add to your Cargo.toml:
[]
= "0.1.0-alpha.2"
use *;
Requirements: Rust 1.85+
Documentation
Full API Documentation - Complete reference for all types, traits, and functions
Key modules:
sans::build- Create coroutines (once,repeat,init_once)sans::compose- Combine coroutines (chain,map_input,map_yield)sans::concurrent- Concurrent execution (join,poll)sans::run- Execute pipelines (handle,handle_async)
License: See LICENSE | Contributing: TBD