ifc_lite_geometry/representation/
refusal.rs1#[derive(Debug)]
8pub enum WalkRefusal {
9 Cyclic,
11 TooDeep { max_depth: u32 },
13 MissingSource,
15 UnresolvedSource,
17 MissingMappedRepresentation,
19 UnresolvedMappedRepresentation,
21 MissingItems,
23 #[non_exhaustive]
25 Budget { max_levels: u32, details: WalkBudgetRefusal },
26 Decode(ifc_lite_core::Error),
28}
29
30#[derive(Debug)]
33pub struct WalkBudgetRefusal(Box<(&'static str, u64)>);
34
35impl WalkBudgetRefusal {
36 pub fn budget(&self) -> &'static str { self.0.0 }
37 pub fn reached(&self) -> u64 { self.0.1 }
38}
39
40const _: () = assert!(
42 std::mem::size_of::<WalkRefusal>() <= std::mem::size_of::<ifc_lite_core::Error>()
43);
44
45impl WalkRefusal {
46 #[cold]
47 #[inline(never)]
48 pub(crate) fn work_budget(max_levels: u32, budget: &'static str, reached: u64) -> Self {
49 Self::Budget { max_levels, details: WalkBudgetRefusal(Box::new((budget, reached))) }
50 }
51
52 pub fn into_error(self, item: u32) -> crate::Error {
56 let msg = match self {
57 WalkRefusal::Cyclic => format!("Detected cyclic IfcMappedItem reference at #{item}"),
58 WalkRefusal::TooDeep { max_depth } => format!(
59 "MappedItem nesting exceeded maximum depth of {max_depth} at #{item}"
60 ),
61 WalkRefusal::Budget { max_levels, .. } => format!(
62 "Representation expansion exceeded the work budget of {max_levels} levels or item references at #{item}"
63 ),
64 WalkRefusal::MissingSource => "MappedItem missing MappingSource".to_string(),
65 WalkRefusal::UnresolvedSource => "Failed to resolve MappingSource".to_string(),
66 WalkRefusal::MissingMappedRepresentation => {
67 "RepresentationMap missing MappedRepresentation".to_string()
68 }
69 WalkRefusal::UnresolvedMappedRepresentation => {
70 "Failed to resolve MappedRepresentation".to_string()
71 }
72 WalkRefusal::MissingItems => "Representation missing Items".to_string(),
73 WalkRefusal::Decode(error) => return crate::Error::CoreError(error),
74 };
75 crate::Error::geometry(msg)
76 }
77}