1use std::fmt;
4use std::time::Duration;
5
6pub trait HandleEvent: fmt::Debug + Sync + Send {
8    #[allow(unused_variables)]
12    fn handle_acquire(&self, event: AcquireEvent) {}
13
14    #[allow(unused_variables)]
18    fn handle_release(&self, event: ReleaseEvent) {}
19
20    #[allow(unused_variables)]
24    fn handle_checkout(&self, event: CheckoutEvent) {}
25
26    #[allow(unused_variables)]
30    fn handle_timeout(&self, event: TimeoutEvent) {}
31
32    #[allow(unused_variables)]
34    fn handle_checkin(&self, event: CheckinEvent) {}
35}
36
37#[derive(Copy, Clone, Debug)]
39pub struct NopEventHandler;
40
41impl HandleEvent for NopEventHandler {}
42
43#[derive(Debug)]
45pub struct AcquireEvent {
46    pub(crate) id: u64,
47}
48
49impl AcquireEvent {
50    #[inline]
52    pub fn connection_id(&self) -> u64 {
53        self.id
54    }
55}
56
57#[derive(Debug)]
59pub struct ReleaseEvent {
60    pub(crate) id: u64,
61    pub(crate) age: Duration,
62}
63
64impl ReleaseEvent {
65    #[inline]
67    pub fn connection_id(&self) -> u64 {
68        self.id
69    }
70
71    #[inline]
73    pub fn age(&self) -> Duration {
74        self.age
75    }
76}
77
78#[derive(Debug)]
80pub struct CheckoutEvent {
81    pub(crate) id: u64,
82    pub(crate) duration: Duration,
83}
84
85impl CheckoutEvent {
86    #[inline]
88    pub fn connection_id(&self) -> u64 {
89        self.id
90    }
91
92    #[inline]
94    pub fn duration(&self) -> Duration {
95        self.duration
96    }
97}
98
99#[derive(Debug)]
101pub struct TimeoutEvent {
102    pub(crate) timeout: Duration,
103}
104
105impl TimeoutEvent {
106    #[inline]
108    pub fn timeout(&self) -> Duration {
109        self.timeout
110    }
111}
112
113#[derive(Debug)]
115pub struct CheckinEvent {
116    pub(crate) id: u64,
117    pub(crate) duration: Duration,
118}
119
120impl CheckinEvent {
121    #[inline]
123    pub fn connection_id(&self) -> u64 {
124        self.id
125    }
126
127    #[inline]
129    pub fn duration(&self) -> Duration {
130        self.duration
131    }
132}