1use std::time::{Duration, Instant};
23/// Statistics regarding an object returned by the pool
4#[derive(Clone, Copy, Debug)]
5#[must_use]
6pub struct Metrics {
7/// The instant when this object was created
8pub created: Instant,
9/// The instant when this object was last used
10pub recycled: Option<Instant>,
11/// The number of times the objects was recycled
12pub recycle_count: usize,
13}
1415impl Metrics {
16/// Access the age of this object
17pub fn age(&self) -> Duration {
18self.created.elapsed()
19 }
20/// Get the time elapsed when this object was last used
21pub fn last_used(&self) -> Duration {
22self.recycled.unwrap_or(self.created).elapsed()
23 }
24}
2526impl Default for Metrics {
27fn default() -> Self {
28Self {
29 created: Instant::now(),
30 recycled: None,
31 recycle_count: 0,
32 }
33 }
34}