Type-safe async context propagation for Rust applications.
fastn-context provides a clean, efficient way to manage async operation context and cancellation in Rust applications. It's designed for applications that need to track operation status, handle graceful shutdowns, and manage background tasks.
- Type-safe context management with structured data
- Graceful cancellation using tokio's CancellationToken
- Operation tracking with status and metrics
- Minimal overhead - zero-cost when not used
- Easy integration with existing async code
Add to your Cargo.toml:
[dependencies]
fastn-context = "0.1"use fastn_context::Context;#[fastn_context::main]asyncfnmain() -> eyre::Result<()>{// Your async code here// Context is automatically available and managedOk(())}use fastn_context::{Context,ContextStatus};asyncfnmy_operation(ctx:&Context) -> Result<String,Error>{// Check for cancellation
ctx.cancelled().await;// Update operation status
ctx.update_status("Processing data...").await;// Your business logicOk("result".to_string())}- Web servers - Request context and graceful shutdown
- Background services - Task coordination and cancellation
- CLI tools - Operation status and signal handling
- Distributed systems - Operation tracking and coordination
Licensed under the Universal Permissive License (UPL-1.0).
Contributions welcome! Please open an issue to discuss major changes before submitting a PR.