]> git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch20-web-server/listing-20-14/src/lib.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / doc / book / listings / ch20-web-server / listing-20-14 / src / lib.rs
1 // ANCHOR: here
2 use std::thread;
3
4 pub struct ThreadPool {
5 threads: Vec<thread::JoinHandle<()>>,
6 }
7
8 impl ThreadPool {
9 // --snip--
10 // ANCHOR_END: here
11 /// Create a new ThreadPool.
12 ///
13 /// The size is the number of threads in the pool.
14 ///
15 /// # Panics
16 ///
17 /// The `new` function will panic if the size is zero.
18 // ANCHOR: here
19 pub fn new(size: usize) -> ThreadPool {
20 assert!(size > 0);
21
22 let mut threads = Vec::with_capacity(size);
23
24 for _ in 0..size {
25 // create some threads and store them in the vector
26 }
27
28 ThreadPool { threads }
29 }
30 // --snip--
31 // ANCHOR_END: here
32
33 pub fn execute<F>(&self, f: F)
34 where
35 F: FnOnce() + Send + 'static,
36 {
37 }
38 // ANCHOR: here
39 }
40 // ANCHOR_END: here