1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use curl::easy::Easy;
use std::boxed::Box;
use super::Error;
pub enum Task<T,E> {
Process {
data: T,
configurator: Box<Fn(&mut T,&mut Easy) -> Result<(),Error<E>> + Send + 'static>,
},
Terminate,
}
impl <T,E>Task<T,E> {
pub fn new<F>(payload: T,configurator: F) -> Task<T,E> where F: Send + 'static, F: Fn(&mut T,&mut Easy) -> Result<(),Error<E>> {
let task = Task::Process {
data: payload,
configurator: Box::new(configurator),
};
return task;
}
}
pub fn disassemble_task<T,E>(task: Task<T,E>) -> (T,Box<Fn(&mut T,&mut Easy) -> Result<(),Error<E>> + Send + 'static>) {
match task {
Task::Process { data, configurator } => {
return (data, configurator);
},
_ => {
panic!("Unable to disassemble task");
}
}
}
pub fn generate_terminate_task<T,E>() -> Task<T,E> {
Task::Terminate
}
pub fn is_terminate_task<T,E>(task: &Task<T,E>) -> bool {
match task {
&Task::Terminate => true,
_ => false,
}
}