Thanks to visit codestin.com
Credit goes to lib.rs

2 releases

Uses new Rust 2024

0.0.2 Jul 24, 2025
0.0.1 Apr 13, 2025

#9 in #arc-mutex

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

79 downloads per month

MIT/Apache

12KB
243 lines

spawn

Simple IPC-based RPC for forked processes.

Usage

use std::sync::{Arc, Mutex};
use spawn::*;

#[derive(Debug, Clone)]
struct TestWorker {
    count: Arc<Mutex<u32>>,
}

impl WorkerTaskHandler for TestWorker {
    type Req = String;
    type Resp = String;
    type Error = std::io::Error;

    fn init() -> Result<Self, Self::Error> {
        Ok(TestWorker {
            count: Arc::new(Mutex::new(0)),
        })
    }

    fn handle_task(&mut self, task: Self::Req) -> Result<Self::Resp, Self::Error> {
        let mut count = self.count.lock().unwrap();
        *count += 1;
        Ok(format!("Task {} handled. Count: {}", task, *count))
    }
}

fn main() {
    let spawner = Spawner::<TestWorker>::new()?;
    let worker = spawner.spawn()?;

    let task = "Test Task".to_string();
    let response = worker.execute(&task)?;

    assert_eq!(response, format!("Task {} handled. Count: 1", task));

    Ok(())
}

Dependencies

~5–27MB
~505K SLoC