ifc_lite_geometry/
pending_diagnostics.rs1use super::{take_pending_mapped_bool_failures, BoolFailure, PENDING_MAPPED_BOOL_FAILURES};
5use ifc_lite_core::IfcType;
6use std::marker::PhantomData;
7
8#[derive(Debug, Default)]
10struct SourceReports {
11 curve_capped: bool,
12 face_refused: Vec<IfcType>,
13}
14
15#[derive(Debug, Default)]
16struct Pending {
17 source: SourceReports,
18 mapped: Vec<BoolFailure>,
19}
20impl Pending {
21 fn take_current() -> Self {
22 Self {
23 source: SourceReports {
24 curve_capped: crate::processors::take_curve_capped(),
25 face_refused: crate::processors::take_face_refused(),
26 },
27 mapped: take_pending_mapped_bool_failures(),
28 }
29 }
30 fn publish(self) {
31 crate::processors::restore_reports(self.source.curve_capped, &self.source.face_refused);
32 PENDING_MAPPED_BOOL_FAILURES.with(|pending| pending.borrow_mut().extend(self.mapped));
33 }
34}
35
36#[derive(Debug, Default)]
40pub struct PendingDiagnosticState {
41 pending: Pending,
42}
43impl PendingDiagnosticState {
44 pub fn new() -> Self {
45 Self::default()
46 }
47
48 pub fn adopt_current_mapped(&mut self) {
52 let mut older = take_pending_mapped_bool_failures();
53 older.append(&mut self.pending.mapped);
54 self.pending.mapped = older;
55 }
56
57 pub fn with_scope<T>(&mut self, work: impl FnOnce() -> T) -> T {
62 let caller = Pending::take_current();
63 std::mem::take(&mut self.pending).publish();
64 let _scope = Scope {
65 owner: self,
66 caller: Some(caller),
67 _thread_bound: PhantomData,
68 };
69 work()
70 }
71
72 pub fn publish_pending(&mut self) {
77 std::mem::take(&mut self.pending).publish();
78 }
79}
80
81struct Scope<'a> {
82 owner: &'a mut PendingDiagnosticState,
83 caller: Option<Pending>,
84 _thread_bound: PhantomData<*const ()>,
85}
86impl Drop for Scope<'_> {
87 fn drop(&mut self) {
88 self.owner.pending = Pending::take_current();
89 if let Some(caller) = self.caller.take() {
90 caller.publish();
91 }
92 }
93}
94
95#[cfg(test)]
96#[path = "pending_diagnostics_tests.rs"]
97mod tests;