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
51
52
//! A point-in-time snapshot of pool occupancy.
/// A snapshot of how many resources a [`Pool`](crate::Pool) holds.
///
/// Returned by [`Pool::status`](crate::Pool::status). The counts are read under
/// the pool's lock, but in a concurrent program they are stale the instant they
/// are returned — treat them as a gauge for logging and metrics, not as a value
/// to branch on for correctness.
///
/// The invariant `size == idle + in_use` holds for each individual snapshot.
///
/// # Examples
///
/// ```
/// use pool_mod::{Manager, Pool};
/// use std::convert::Infallible;
///
/// struct Nothing;
/// impl Manager for Nothing {
/// type Resource = ();
/// type Error = Infallible;
/// fn create(&self) -> Result<(), Infallible> { Ok(()) }
/// fn recycle(&self, _r: &mut ()) -> Result<(), Infallible> { Ok(()) }
/// }
///
/// let pool = Pool::builder(Nothing).max_size(4).min_idle(2).build()
/// .expect("configuration is valid");
///
/// let status = pool.status();
/// assert_eq!(status.size, 2);
/// assert_eq!(status.idle, 2);
/// assert_eq!(status.in_use, 0);
/// assert_eq!(status.max_size, 4);
/// assert_eq!(status.size, status.idle + status.in_use);
/// ```