sansio
An IO-free Rust networking framework that makes it easy to build protocols, application clients, and servers using the Sans-IO pattern.
Inspired by Netty and Wangle, sansio brings the power of pipeline-based protocol composition to Rust.
Features
- Sans-IO Design: Complete separation of protocol logic from I/O operations
- Pipeline Architecture: Chain handlers to build complex protocols from simple components
- Type-Safe Composition: Rust's type system ensures handlers connect correctly
- Runtime Agnostic: Works with tokio async runtime
- Testable: Test protocol logic without any I/O
Core Concepts
Pipeline
The Pipeline is a chain of Handlers that process inbound and outbound data:
use Pipeline;
let pipeline = new;
pipeline.add_back;
pipeline.add_back;
pipeline.add_back;
pipeline.finalize
Handler
Each Handler processes messages flowing through the pipeline with four associated types:
Rin: Input type for inbound messagesRout: Output type for inbound messagesWin: Input type for outbound messagesWout: Output type for outbound messages
use ;
Protocol
The Protocol trait provides a simpler, fully Sans-IO alternative for protocol implementation:
use Protocol;
Quick Start
Add sansio to your Cargo.toml:
[]
= "0.0.5"
Build a simple pipeline:
use ;
use Rc;
// Define your handler
;
Using with a Runtime
sansio is purely Sans-IO without any runtime dependencies. For async runtime support, use the separate sansio-executor crate:
[]
= "0.0.7"
= "0.0.7" # For runtime support
use LocalExecutorBuilder;
See the sansio-executor documentation for more details on runtime support.
Documentation
Examples
See the examples crate for complete working examples:
- UDP chat server with pipeline-based protocol processing
- Handler composition and shared state management
Run an example:
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.