use std::fmt;
use std::sync::Arc;
use std::time::{Duration, Instant};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Overdue {
id: u32,
elapsed: Duration,
}
impl Overdue {
pub(crate) const fn new(id: u32, elapsed: Duration) -> Self {
Self { id, elapsed }
}
#[must_use]
pub const fn id(&self) -> u32 {
self.id
}
#[must_use]
pub const fn elapsed(&self) -> Duration {
self.elapsed
}
}
#[derive(Clone)]
pub(super) struct Report {
pub(super) at: Instant,
report: Arc<dyn Fn(Overdue) + Send + Sync>,
}
impl Report {
pub(super) fn new(at: Instant, report: impl Fn(Overdue) + Send + Sync + 'static) -> Self {
Self {
at,
report: Arc::new(report),
}
}
pub(super) fn call(&self, overdue: Overdue) {
(self.report)(overdue);
}
}
impl fmt::Debug for Report {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Report")
.field("at", &self.at)
.finish_non_exhaustive()
}
}