crumbkit_process/
overdue.rs1use std::fmt;
4use std::sync::Arc;
5use std::time::{Duration, Instant};
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10#[non_exhaustive]
11pub struct Overdue {
12 id: u32,
13 elapsed: Duration,
14}
15
16impl Overdue {
17 pub(crate) const fn new(id: u32, elapsed: Duration) -> Self {
18 Self { id, elapsed }
19 }
20
21 #[must_use]
24 pub const fn id(&self) -> u32 {
25 self.id
26 }
27
28 #[must_use]
30 pub const fn elapsed(&self) -> Duration {
31 self.elapsed
32 }
33}
34
35#[derive(Clone)]
37pub(super) struct Report {
38 pub(super) at: Instant,
39 report: Arc<dyn Fn(Overdue) + Send + Sync>,
40}
41
42impl Report {
43 pub(super) fn new(at: Instant, report: impl Fn(Overdue) + Send + Sync + 'static) -> Self {
45 Self {
46 at,
47 report: Arc::new(report),
48 }
49 }
50
51 pub(super) fn call(&self, overdue: Overdue) {
53 (self.report)(overdue);
54 }
55}
56
57impl fmt::Debug for Report {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 f.debug_struct("Report")
60 .field("at", &self.at)
61 .finish_non_exhaustive()
62 }
63}