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

ambee/giterated

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

More restructuring

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨10b7b7c

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