[][src]Trait employer::JobDescription

pub trait JobDescription<I>: Send + Sync {
    type Output;
    fn work(&self, input: I) -> Self::Output;
}

A description of a job

This trait defines work to be done through an Employer. This crate provides two implementations. A stateless one, and a stateful one.

Stateless Example

JobDescription<I, Output = O> is emplemented for all F where F: Fn(I) -> O + Send + Sync. This is the basic stateless implementation.

use employer::*;

let employer = Employer::new(|i| i + 1); // No state, just a function

employer.start(1);

assert_eq!(employer.wait_for(&1).unwrap(), 2);

Stateful Example

JobDescription<I, Output = O> is emplemented for all (S, F) where F: Fn(&S, I) -> O + Send + Sync, S: Send + Sync. This is the basic stateful implementation. State is shared accross threads. The function Employer::with_state makes this easier to construct.

use employer::*;

let employer = Employer::with_state(3, |state: &i32, i| i + *state); // A state and a function

employer.start(1);

assert_eq!(employer.wait_for(&1).unwrap(), 4);

Associated Types

type Output

The job output type

Loading content...

Required methods

fn work(&self, input: I) -> Self::Output

Do the job

Loading content...

Implementations on Foreign Types

impl<'a, F, I, O, S> JobDescription<I> for (S, F) where
    F: Fn(&S, I) -> O + Send + Sync,
    S: Send + Sync
[src]

type Output = O

Loading content...

Implementors

impl<F, I, O> JobDescription<I> for F where
    F: Fn(I) -> O + Send + Sync
[src]

type Output = O

Loading content...