Effect-rs
A high-performance, strictly-typed, functional effect system for Rust.
⚠️ Note: This project is currently in active development / alpha stage.
Effect-rs brings the power of functional effect systems (inspired by ZIO, Cats Effect) to the Rust ecosystem. It provides a robust framework for building asynchronous, concurrent, and resilient applications with ease.
Key Features
- Effect<R, E, A>: The core generic type representing a lazy computation that requires an environment
R, may fail withE, or succeed withA. - Structured Concurrency: Lightweight fibers with automatic cancellation propagation and resource safety.
- Dependency Injection: Type-safe environment management built directly into the
Effecttype. - Software Transactional Memory (STM): Composable, atomic transactions for managing shared state without deadlocks.
- Streams: Purely functional, pull-based streams for processing data pipelines efficiently.
- Resilience: Built-in
ScheduleandRetrypolicies to handle failures gracefully. - Testkit: Deterministic
TestRuntimeandTestClockfor reliable, time-dependent testing.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
Quick Start
Basic Effect
use ;
Dependency Injection
use ;
use Arc;
Concurrency & Fibers
use ;
use Duration;
Philosophy
Effect-rs aims to bridge the gap between Rust's zero-cost abstractions and the expressive power of functional programming. By treating side effects as values, we gain:
- Referential Transparency: Easier reasoning and refactoring.
- ** composability**: Build complex logic from simple, reusable blocks.
- Type Safety: Errors and dependencies are explicit in the type signature.
Running Examples
The project includes several examples demonstrating key features. You can run them using the provided Makefile:
- Transactional Bank (STM):
make run-bank - Stream Pipeline:
make run-stream - HTTP Service Mock:
make run-http
Running Benchmarks
Performance benchmarks are available for core components:
- Run All:
make bench - Fiber Operations:
make bench-fiber - Runtime Overhead:
make bench-runtime - STM Transactions:
make bench-stm - Stream Processing:
make bench-stream
Or using Cargo directly:
License
This project is licensed under the MIT License.