1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use trace;
use ;
// use crate::config::utils::replace_env_vars;
use crateFLUX_REGISTRY;
use crateFlux;
static ARGS: &str = "args";
static TYPE: &str = "type";
/// Implements serialization for `Box<dyn Flux>`.
///
/// This implementation ensures that the `Flux` type is correctly identified and serialized
/// along with its data. It uses the global `FLUX_REGISTRY` to map the concrete `Flux` type
/// to its string representation.
///
/// # Errors
///
/// Returns a serialization error if the `Flux` type is unknown.
// impl Serialize for Box<dyn Flux> {
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// let type_name = {
// let registry = FLUX_REGISTRY.lock().unwrap();
// registry.creators.iter()
// .find_map(|(name, creator)| {
// let flux = self.as_ref();
// let temp_flux = creator(&serde_json::Value::Null).unwrap();
// if temp_flux.as_ref().type_id() == flux.type_id() {
// Some(name.clone())
// } else {
// None
// }
// })
// .ok_or_else(|| Error::custom("Unknown Flux type"))?
// };
//
// let mut state = serializer.serialize_struct("Flux", 2)?;
// state.serialize_field("type", &type_name)?;
// state.serialize_field("data", self)?;
// state.end()
// }
// }
use ;
use SerializeStruct;
use Value;
/// Implements deserialization for `Box<dyn Flux>`.
///
/// This implementation reconstructs the `Flux` type from its string representation and
/// deserializes its data. It uses the global `FLUX_REGISTRY` to find the appropriate
/// constructor for the given `Flux` type.
///
/// # Errors
///
/// Returns a deserialization error if the `Flux` type is unknown or if there is an error
/// during the creation of the `Flux` instance.
// impl<'de> Deserialize<'de> for Box<dyn Flux> {
// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
// where
// D: Deserializer<'de>,
// {
// trace!("Deserializing Box<dyn Flux>");
// let value: serde_json::Value = serde::Deserialize::deserialize(deserializer)?;
//
// //////////////////////////
// // TYPE
// //////////////////////////
// let type_name = value.get(TYPE)
// .and_then(serde_json::Value::as_str)
// .ok_or_else(|| DeError::missing_field(TYPE))?
// .to_string();
// trace!("Deserializing Flux type: {}", type_name);
//
// //////////////////////////
// // ARGS
// //////////////////////////
// let args = value.get(ARGS)
// .ok_or_else(|| DeError::missing_field(ARGS))?;
//
// trace!("Deserializing Flux {:?}: {:?}", type_name, args);
//
// //////////////////////////
// let registry = FLUX_REGISTRY.lock().unwrap();
// trace!("Getting Flux constructor");
// let constructor = registry.creators.get(&type_name)
// .ok_or_else(|| DeError::custom("Unknown Flux type"))?;
//
// trace!("Creating Flux instance");
// constructor(&args).map_err(|e| DeError::custom(e.to_string()))
// }
// }