simple/
simple.rs

1use std::mem;
2
3use atomic_pool::{pool, Box};
4
5#[derive(Debug)]
6struct Packet(u32);
7
8pool!(PacketPool: [Packet; 4]);
9
10fn main() {
11    let box1 = Box::<PacketPool>::new(Packet(1));
12    println!("allocated: {:?}", box1);
13
14    let box2 = Box::<PacketPool>::new(Packet(2));
15    println!("allocated: {:?}", box2);
16
17    let box3 = Box::<PacketPool>::new(Packet(3));
18    println!("allocated: {:?}", box3);
19
20    let box4 = Box::<PacketPool>::new(Packet(4));
21    println!("allocated: {:?}", box4);
22
23    let box5 = Box::<PacketPool>::new(Packet(5));
24    println!("5th allocation fails because the pool is full: {:?}", box5);
25
26    println!("dropping another allocation...");
27    mem::drop(box1);
28
29    let box5 = Box::<PacketPool>::new(Packet(5));
30    println!("5th allocation now works: {:?}", box5);
31}