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
45
46
47
48
49
50
use allocator::{Allocate, Thread, Process, Binary};
use {Push, Pull, Data};
pub enum Generic {
Thread(Thread),
Process(Process),
Binary(Binary),
}
impl Generic {
pub fn index(&self) -> usize {
match self {
&Generic::Thread(ref t) => t.index(),
&Generic::Process(ref p) => p.index(),
&Generic::Binary(ref b) => b.index(),
}
}
pub fn peers(&self) -> usize {
match self {
&Generic::Thread(ref t) => t.peers(),
&Generic::Process(ref p) => p.peers(),
&Generic::Binary(ref b) => b.peers(),
}
}
pub fn allocate<T: Data>(&mut self) -> (Vec<Box<Push<T>>>, Box<Pull<T>>, Option<usize>) {
match self {
&mut Generic::Thread(ref mut t) => t.allocate(),
&mut Generic::Process(ref mut p) => p.allocate(),
&mut Generic::Binary(ref mut b) => b.allocate(),
}
}
}
impl Allocate for Generic {
fn index(&self) -> usize { self.index() }
fn peers(&self) -> usize { self.peers() }
fn allocate<T: Data>(&mut self) -> (Vec<Box<Push<T>>>, Box<Pull<T>>, Option<usize>) {
self.allocate()
}
}