JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Structure refactoring

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨a8f41ac

⁨giterated-core/src/types/mod.rs⁩ - ⁨2098⁩ bytes
Raw
1 #[derive(Default, Clone)]
2 pub struct TypeMetadata {
3 pub objects: HashMap<&'static str, &'static VTable<Object>>,
4 pub operations: HashMap<ObjectOperationPair<'static>, &'static VTable<Operation>>,
5 pub settings: HashMap<ObjectSettingPair<'static>, &'static VTable<Setting>>,
6 pub values: HashMap<ObjectValuePair<'static>, &'static VTable<Value>>,
7 }
8
9 impl TypeMetadata {
10 pub unsafe fn from_static() -> &'static Self {
11 giterated_static_runtime::get_type_metadata_reference()
12 .cast::<TypeMetadata>()
13 .as_ref()
14 }
15
16 pub fn register_object(&mut self, object_kind: &'static str, vtable: &'static VTable<Object>) {
17 trace!("Registering type metadata for {}", object_kind);
18
19 self.objects.insert(object_kind, vtable);
20 }
21
22 pub fn register_operation(
23 &mut self,
24 object_kind: &'static str,
25 operation_name: &'static str,
26 vtable: &'static VTable<Operation>,
27 ) {
28 trace!(
29 "Registering operation metadata for {}::{}",
30 object_kind,
31 operation_name
32 );
33
34 self.operations.insert(
35 ObjectOperationPair {
36 object_kind,
37 operation_name,
38 },
39 vtable,
40 );
41 }
42
43 pub fn register_setting(
44 &mut self,
45 object_kind: &'static str,
46 setting_name: &'static str,
47 vtable: &'static VTable<Setting>,
48 ) {
49 trace!("Registering setting {}::{}", object_kind, setting_name);
50
51 self.settings.insert(
52 ObjectSettingPair {
53 object_kind,
54 setting_name,
55 },
56 vtable,
57 );
58 }
59
60 pub fn register_value(
61 &mut self,
62 object_kind: &'static str,
63 value_name: &'static str,
64 vtable: &'static VTable<Value>,
65 ) {
66 trace!("Registering value {}::{}", object_kind, value_name);
67
68 self.values.insert(
69 ObjectValuePair {
70 object_kind,
71 value_name,
72 },
73 vtable,
74 );
75 }
76 }
77
78