Expand description
§Sans: Composable Coroutine-Based Programming
Build composable computations that can yield intermediate values and be driven to completion by external input.
§Core Traits
Sans<I, O>: Stateful computations that process input and yield valuesInitSans<I, O>: Computations that provide initial output before processing input
§Key Features
- Composable: Chain coroutines together with
.chain() - Transformable: Use
.map_input(),.map_yield(),.map_done() - Async Support: Both sync and async execution with
handle()andhandle_async()
§Example
use sans::prelude::*;
// Build a pipeline that yields initial value, processes input, then finishes
let pipeline = init_once(10, |x: i32| x * 2) // Yields 10, then multiplies input by 2
.chain(once(|x: i32| x + 1)); // Adds 1 to input, then completes
// Drive the pipeline with responses to each yield
let result = handle(pipeline, |output| output + 5);§Module Organization
This library is organized by capability:
build- Creating new coroutinescompose- Chaining and transforming coroutinesresult- Result combinators for error handling in coroutinespoll- Universal adapter implementing bothSansandInitSansfor bridging APIsconcurrent- Running multiple coroutines concurrentlysequential- Running coroutines one after anotherrun- Executing coroutine pipelinesiter- Iterator adapters forSans<(), O>andInitSans<(), O>prelude- Common imports for quick start
§Common Functions
Building Coroutines:
once(f)- Apply function once, then completerepeat(f)- Apply function repeatedlyinit(value, coroutine)- Wrap aSanswith an initial output (forand_then)init_once(value, f)- Yield initial value, then apply function oncechain(a, b)- Run coroutineato completion, then run coroutineb
Execution:
handle(coroutine, responder)- Drive computation with sync responseshandle_async(coroutine, responder)- Drive computation with async responses
Modules§
- build
- Building coroutines from scratch
- compose
- Combining coroutines together
- concurrent
- Run multiple coroutines concurrently
- iter
- Iterator adapters for Sans coroutines with unit input.
- poll
- Polling for both
SansandInitSans - prelude
- Commonly used imports
- result
- Result combinators for error handling in coroutines.
- run
- Running coroutines to completion
- sequential
- Run coroutines one after another
Structs§
Enums§
- Step
- Result of a computation step, either yielding a value to continue or completing with a final value.