Skip to main content

Crate tarnish

Crate tarnish 

Source
Expand description

§tarnish, a process Isolation Library

tarnish provides process-level isolation for running Rust code with automatic panic recovery and graceful shutdown. Implement the Task trait and let Process handle the lifecycle management.

§Features

  • Trait-based API: Implement Task trait with your business logic
  • Auto-restart on panic: Child processes automatically restart if they panic
  • Graceful shutdown: Automatic cleanup when Process is dropped
  • Type-safe: Generic over your worker type
  • Zero dependencies: Built entirely on Rust standard library

§Example

use tarnish::{Task, Process};

#[derive(Default)]
struct Calculator;

impl Task for Calculator {
    type Input = String;
    type Output = String;
    type Error = String;

    fn run(&mut self, input: String) -> Result<String, String> {
        let num: i32 = input.parse()
            .map_err(|e| format!("Parse error: {e}"))?;
        Ok(format!("Result: {}", num * 2))
    }
}

fn main() {
    tarnish::main::<Calculator>(parent_main);
}

fn parent_main() {
    let mut process = Process::<Calculator>::spawn()
        .expect("Failed to spawn process");

    match process.call("42".to_string()) {
        Ok(result) => println!("Success: {result}"),
        Err(e) => eprintln!("Error: {e}"),
    }
}

§Clippy Lint Allowances

This crate allows certain restrictive lints where they don’t add value:

  • missing_docs_in_private_items: Internal implementation details don’t need docs
  • pattern_type_mismatch: Pattern matching on internal enums is intentional
  • multiple_crate_versions: Acceptable for development dependencies

Macros§

task
Run code in an isolated subprocess with automatic crash recovery

Structs§

Process
Handle to a worker process
ProcessPool
A pool of worker processes for concurrent task execution.

Enums§

ProcessError
Error types for Process operations

Traits§

MessageDecode
Trait for decoding messages received over process boundaries
MessageEncode
Trait for encoding messages to send over process boundaries
Task
Trait for implementing worker logic that runs in an isolated process

Functions§

main
Handle worker process mode in your main function
worker_main
Low-level entry point for worker process detection.

Type Aliases§

Result