Skip to content

Repository files navigation

fastn-context

Type-safe async context propagation for Rust applications.

Overview

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.

Features

  • 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

Quick Start

Add to your Cargo.toml:

[dependencies]
fastn-context = "0.1"

Basic Usage

use fastn_context::Context;#[fastn_context::main]asyncfnmain() -> eyre::Result<()>{// Your async code here// Context is automatically available and managedOk(())}

With Custom Context

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())}

Documentation

Use Cases

  • 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

License

Licensed under the Universal Permissive License (UPL-1.0).

Contributing

Contributions welcome! Please open an issue to discuss major changes before submitting a PR.

About

Type-safe async context propagation for Rust applications

Resources

Code of conduct

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages