parsli 0.0.3

Parallel status lines for Rust
Documentation
use std::collections::HashMap;
use std::sync::Arc;
use crate::Line;

type TaskArgs<S> = (String, HashMap<String, S>, Line);
type TaskOutput<S> = Result<S, String>;

pub trait TaskFn<S> = Fn<TaskArgs<S>, Output=TaskOutput<S>> + Send + Sync + 'static;

#[derive(Clone)]
pub struct Task<S> {
    inner: Arc<dyn TaskFn<S>>,
}

impl<S> Task<S> {
    pub fn new<F>(f: F) -> Self where F: TaskFn<S> {
        Self { inner: Arc::new(f) }
    }
}

impl<S> FnOnce<TaskArgs<S>> for Task<S> {
    type Output = TaskOutput<S>;

    extern "rust-call" fn call_once(self, args: TaskArgs<S>) -> Self::Output {
        self.inner.as_ref().call_once(args)
    }
}

impl<S> FnMut<TaskArgs<S>> for Task<S> {
    extern "rust-call" fn call_mut(&mut self, args: TaskArgs<S>) -> Self::Output {
        self.inner.as_ref().call_mut(args)
    }
}

impl<S> Fn<TaskArgs<S>> for Task<S> {
    extern "rust-call" fn call(&self, args: TaskArgs<S>) -> Self::Output {
        self.inner.as_ref().call(args)
    }
}