ifc_lite_export/plan/
removal.rs

1// SPDX-License-Identifier: MPL-2.0
2//! What a plan removed from the output and why, as [`super::WriteReport`]
3//! reports it, so a caller reconciling its own model with the file reads
4//! the executor's reason instead of predicting it.
5//!
6//! A record can go for more than one reason. It reports `Requested` when the
7//! plan deletes it, else `Replaced` when a patch removed it, else `Unhosted`
8//! for an opening or projection that lost its host relationship; otherwise
9//! the reason the delete cascade found first. The cascade walks the plan's
10//! deletes in id order, so the same plan reports the same reasons on every
11//! run. Finding every reason a record also has would mean reading records
12//! the cascade has already removed again, so it is not done: the cost stays
13//! one map entry per removal, recorded where the removal already happens.
14
15/// Why a record is not in the output. When the cascade reaches a removed
16/// record again for another reason, the earlier one in this order is kept.
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
18#[non_exhaustive]
19pub enum RemovalReason {
20    /// The plan deletes it (`Disposition::Delete`).
21    Requested,
22    /// A patch replaced it: an old placement chain, a product's old body
23    /// and what annotated it, or a relationship the patch's object moved
24    /// out of.
25    Replaced,
26    /// An opening or projection left without its host relationship: IFC ties
27    /// each to exactly one element.
28    Unhosted,
29    /// It names a removed record through a single-valued attribute (a
30    /// relationship whose relating object went, a placement relative to a
31    /// removed one), so it cannot be written without a dangling reference.
32    Dangling,
33    /// A relationship or presentation layer whose mandatory member list the
34    /// plan's deletes emptied. One a patch's copy-on-write emptied by moving
35    /// its object to a new relationship is `Replaced`.
36    Emptied,
37    /// Nothing refers to it once the records that used it went: a property
38    /// set, a placement chain, geometry.
39    Released,
40}
41
42/// One record the plan removed, and why.
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44#[non_exhaustive]
45pub struct Removal {
46    /// Its express id in the source.
47    pub express_id: u32,
48    pub reason: RemovalReason,
49}
50
51impl RemovalReason {
52    /// The reason a record that went for both `self` and `other` reports.
53    pub(crate) fn first(self, other: Self) -> Self {
54        self.min(other)
55    }
56}
57
58impl Removal {
59    pub fn new(express_id: u32, reason: RemovalReason) -> Self {
60        Self { express_id, reason }
61    }
62}
63
64#[cfg(test)]
65#[path = "removal_tests.rs"]
66mod tests;