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
//===================================================================================================================================================================================//
//
// /$$ /$$ /$$ /$$$$$$$ /$$ /$$
// | $$$ | $$ | $$ | $$__ $$ |__/ | $$
// | $$$$| $$ /$$$$$$ /$$$$$$$ /$$$$$$ | $$ \ $$ /$$$$$$ /$$$$$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$
// | $$ $$ $$ /$$__ $$ /$$__ $$ /$$__ $$ | $$$$$$$/ /$$__ $$ /$$__ $$| $$ /$$_____/|_ $$_/ /$$__ $$| $$ | $$
// | $$ $$$$| $$ \ $$| $$ | $$| $$$$$$$$ | $$__ $$| $$$$$$$$| $$ \ $$| $$| $$$$$$ | $$ | $$ \__/| $$ | $$
// | $$\ $$$| $$ | $$| $$ | $$| $$_____/ | $$ \ $$| $$_____/| $$ | $$| $$ \____ $$ | $$ /$$| $$ | $$ | $$
// | $$ \ $$| $$$$$$/| $$$$$$$| $$$$$$$ | $$ | $$| $$$$$$$| $$$$$$$| $$ /$$$$$$$/ | $$$$/| $$ | $$$$$$$
// |__/ \__/ \______/ \_______/ \_______/ |__/ |__/ \_______/ \____ $$|__/|_______/ \___/ |__/ \____ $$
// /$$ \ $$ /$$ | $$
// | $$$$$$/ | $$$$$$/
// \______/ \______/
//
//===================================================================================================================================================================================//
//?
//? Created by LunaticWyrm467 and others.
//?
//? All code is licensed under the MIT license.
//? Feel free to reproduce, modify, and do whatever.
//?
//!
//! Provides and initializes a global state which keeps track of `Node` deserializer functions.
//!
use Arc;
use HashMap;
use DashMap;
pub use Value;
use crateNode;
use crateExportable;
/// Represents a static node registry.
/// This contains an ID which is represented as the Node's name, followed by a function pointer
/// which is used to convert a map which is parsed from a scene file back into its respective node.
///
/// # Note
/// The reason why we use the name and not the `TypeID` is because the `TypeID` can change across rust
/// versions and builds, while the name of the node is fully controlled by the programmer.
/// This however also has its downsides, such as the moving of the module that a node is defined
/// in, or renaming the node itself resulting in the invalidation of prior save data.
///
/// Furthermore, the interesting thing about using a `HashMap<Box<str>, Box<dyn Serializable>>`/`HashMap<Box<str>, toml::Value>
/// as the opaque representation for a `Node`'s owned fields is that a derive macro can easily generate
/// the deserialization function and register it to the `NODE_REGISTRY`. An example of a generate
/// function is shown below:
/// ```rust, ignore
/// class! {
/// declare NodeName;
///
/// let field_a: String;
/// let field_b: u32;
/// let field_c: Vec<f32>;
/// }
///
/// // This function was generated for `NodeName` via the `Register` derive macro, which is implemented via `class!`:
/// fn deserialize(owned_state: SFieldMap) -> Result<Box<dyn Node>, String> {
/// let node: NodeName = NodeName::load_from_owned(
/// String::from_value(*owned_state.remove("field_a").ok_or("corrupt save data; `field_a` missing".to_string())?).ok_or("corrupt save data; `field_a` invalid type".to_string())?,
/// u32::from_value(*owned_state.remove("field_b").ok_or("corrupt save data; `field_b` missing".to_string())?).ok_or("corrupt save data; `field_b` invalid type".to_string())?,
/// Vec::from_value(*owned_state.remove("field_c").ok_or("corrupt save data; `field_c` missing".to_string())?).ok_or("corrupt save data; `field_c` invalid type".to_string())?,
/// );
/// Box::new(node)
/// }
/// ```
static mut NODE_REGISTRY: = None;
/// Used as a alias for a map containing the unserialized fields of a node, along with its associated values.
pub type FieldMap = ;
/// Used as an alias for a map containing the serialized fields of a node, along with its associated values.
pub type SFieldMap = ;
/// Used as an alias for the deserializer function.
pub type Deserializer = dyn Fn ;
/// Used as an unsafe cell for the registry to allow for the sharing of values.
unsafe
unsafe
/// Registers a deserializing function under a node's name.
///
/// # Safety
/// This should only be called from the main thread or from one thread at a time before the main
/// function is invoked via `ctor`.
pub unsafe
/// Takes a `SFieldMap` and deserializes it into a `Node` with a bare `NodeBase`.