1extern crate syncpool;
2
3use std::vec;
4use syncpool::prelude::*;
5
6struct BigStruct {
7 a: u32,
8 b: u32,
9 c: Vec<u8>,
10}
11
12impl BigStruct {
13 fn new() -> Self {
14 BigStruct {
15 a: 1,
16 b: 42,
17 c: vec::from_elem(0u8, 0x1_000_000),
18 }
19 }
20
21 fn initializer(mut self: Box<Self>) -> Box<Self> {
22 self.a = 1;
23 self.b = 42;
24 self.c = vec::from_elem(0u8, 0x1_000_000);
25
26 self
27 }
28}
29
30fn main() {
31 call_builder();
32 call_packer();
33}
34
35fn call_builder() {
36 let mut pool = SyncPool::with_builder(BigStruct::new);
37
38 println!("Pool created...");
39
40 let big_box = pool.get();
41
42 assert_eq!(big_box.a, 1);
43 assert_eq!(big_box.b, 42);
44 assert_eq!(big_box.c.len(), 0x1_000_000);
45
46 pool.put(big_box);
47}
48
49fn call_packer() {
50 let mut pool = SyncPool::with_packer(BigStruct::initializer);
51
52 println!("Pool created...");
53
54 let big_box = pool.get();
55
56 assert_eq!(big_box.a, 1);
57 assert_eq!(big_box.b, 42);
58 assert_eq!(big_box.c.len(), 0x1_000_000);
59
60 pool.put(big_box);
61}