cranpose_core/
recycled_node.rs1use crate::{Node, NodeError, NodeId};
2
3#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
5pub enum RecycleOrigin {
6 #[default]
8 Cold,
9 Warm,
11}
12
13pub struct RecycledNode {
16 stable_id: NodeId,
17 pub(crate) node: Box<dyn Node>,
18 origin: RecycleOrigin,
19}
20
21impl RecycledNode {
22 pub(crate) fn new(stable_id: NodeId, mut node: Box<dyn Node>, origin: RecycleOrigin) -> Self {
25 node.prepare_for_recycle();
26 Self {
27 stable_id,
28 node,
29 origin,
30 }
31 }
32
33 pub(crate) fn from_shell(
34 stable_id: NodeId,
35 node: Box<dyn Node>,
36 origin: RecycleOrigin,
37 ) -> Self {
38 Self {
39 stable_id,
40 node,
41 origin,
42 }
43 }
44
45 pub fn stable_id(&self) -> NodeId {
47 self.stable_id
48 }
49
50 pub(crate) fn origin(&self) -> RecycleOrigin {
51 self.origin
52 }
53
54 pub(crate) fn set_origin(&mut self, origin: RecycleOrigin) {
55 self.origin = origin;
56 }
57
58 pub fn node_mut(&mut self) -> &mut dyn Node {
60 self.node.as_mut()
61 }
62
63 pub fn into_parts(self) -> (NodeId, Box<dyn Node>, RecycleOrigin) {
65 (self.stable_id, self.node, self.origin)
66 }
67}
68
69#[derive(Debug, Clone, PartialEq, Eq)]
71pub struct RecycledNodeInsertion {
72 pub id: NodeId,
74 pub stable_id_reused: bool,
76 pub fallback_error: Option<NodeError>,
78}
79
80impl RecycledNodeInsertion {
81 pub(crate) fn reused(stable_id: NodeId) -> Self {
82 Self {
83 id: stable_id,
84 stable_id_reused: true,
85 fallback_error: None,
86 }
87 }
88
89 pub(crate) fn fresh(id: NodeId, fallback_error: Option<NodeError>) -> Self {
90 Self {
91 id,
92 stable_id_reused: false,
93 fallback_error,
94 }
95 }
96}