1use std::panic::{RefUnwindSafe, UnwindSafe};
2use std::rc::Rc;
3use std::sync::Arc;
4
5#[cfg(test)]
6use crate::ObservationBagSnapshot;
7use crate::{Magnitude, ObservationBag, ObservationBagSync, Observations, Sealed};
8
9#[expect(private_bounds, reason = "intentionally sealed trait")]
16pub trait PublishModel: PublishModelPrivate + Sealed {}
17
18pub(crate) trait PublishModelPrivate {
20 fn insert(&self, magnitude: Magnitude, count: usize);
22
23 #[cfg(test)]
25 fn snapshot(&self) -> ObservationBagSnapshot;
26}
27
28#[derive(Debug)]
36pub struct Push {
37 pub(crate) observations: Rc<ObservationBag>,
38}
39
40impl UnwindSafe for Push {}
43impl RefUnwindSafe for Push {}
44
45impl Sealed for Push {}
46impl PublishModel for Push {}
47impl PublishModelPrivate for Push {
48 #[cfg(test)]
49 fn snapshot(&self) -> ObservationBagSnapshot {
50 self.observations.snapshot()
51 }
52
53 fn insert(&self, magnitude: Magnitude, count: usize) {
54 self.observations.insert(magnitude, count);
55 }
56}
57
58#[derive(Debug)]
62pub struct Pull {
63 pub(crate) observations: Arc<ObservationBagSync>,
66}
67
68impl Sealed for Pull {}
69impl PublishModel for Pull {}
70impl PublishModelPrivate for Pull {
71 #[cfg(test)]
72 fn snapshot(&self) -> ObservationBagSnapshot {
73 self.observations.snapshot()
74 }
75
76 fn insert(&self, magnitude: Magnitude, count: usize) {
77 self.observations.insert(magnitude, count);
78 }
79}
80
81#[cfg(test)]
82#[cfg_attr(coverage_nightly, coverage(off))]
83mod tests {
84 use std::panic::{RefUnwindSafe, UnwindSafe};
85
86 use static_assertions::assert_impl_all;
87
88 use super::*;
89
90 assert_impl_all!(Push: UnwindSafe, RefUnwindSafe);
91 assert_impl_all!(Pull: UnwindSafe, RefUnwindSafe);
92}