distillation_shortcut_unit/shared_unit_data.rs
1use cobia::*;
2
3/// The `SharedUnitData` struct holds common data for the distillation shortcut unit.
4///
5/// Each distillation shortcut unit contains a single instance of `SharedUnitData` that holds
6/// information such as the unit's name and validation status. This data is shared across
7/// all components of the unit, including ports, collections, and parameters.
8
9pub(crate) struct SharedUnitData {
10 /// The name of the distillation shortcut unit; used by various components for formatting the error source name.
11 pub name: CapeStringImpl,
12 /// The validation status of the distillation shortcut unit; used by various components to flag the unit as not validated.
13 pub validation_status : cobia::cape_open_1_2::CapeValidationStatus,
14 // The dirty flag for the unit operation. If the unit is dirty, it need saving
15 pub dirty: bool,
16}
17
18/// All objects that need access to SharedUnitData are outlived by its owner, which
19/// is the DistillationShortcutUnit, so in principle we can pass a reference to
20/// a `RefCell<SharedUnitData>` to all objects that need it.
21///
22/// This complicates matters due to the life time specification of those objects.
23///
24/// Instead in this example we prefer to pass a reference counted RefCell, so that
25/// all objects can share the same instance of SharedUnitData, with shared ownership.
26pub type SharedUnitDataRef = std::rc::Rc<std::cell::RefCell<SharedUnitData>>;
27
28impl std::default::Default for SharedUnitData {
29 /// Creates a new instance of `SharedUnitData` with default values.
30 ///
31 /// Implemented to allow deriving Default on classes that reference this.
32 fn default() -> Self {
33 Self {
34 name: std::default::Default::default(),
35 validation_status: cobia::cape_open_1_2::CapeValidationStatus::CapeNotValidated,
36 dirty:false,
37 }
38 }
39}