aboutsummaryrefslogtreecommitdiff
path: root/common/object/src/registry.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-01-07 04:03:34 +0100
committermetamuffin <metamuffin@disroot.org>2026-01-07 04:03:34 +0100
commit7cc5fe5cd008072b99fc470b0ed730f7fa4e2881 (patch)
tree5ae0e65497528342d3b21dd343ace364a61fb82c /common/object/src/registry.rs
parentf932d4de439c6472d34ed4bbf530fca13b84d73a (diff)
downloadjellything-7cc5fe5cd008072b99fc470b0ed730f7fa4e2881.tar
jellything-7cc5fe5cd008072b99fc470b0ed730f7fa4e2881.tar.bz2
jellything-7cc5fe5cd008072b99fc470b0ed730f7fa4e2881.tar.zst
debug inpect impl
Diffstat (limited to 'common/object/src/registry.rs')
-rw-r--r--common/object/src/registry.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/common/object/src/registry.rs b/common/object/src/registry.rs
index 7148efd..4727600 100644
--- a/common/object/src/registry.rs
+++ b/common/object/src/registry.rs
@@ -8,6 +8,16 @@ use crate::Tag;
use log::error;
use std::{any::TypeId, collections::BTreeMap};
+pub mod types {
+ use crate::Object;
+ use std::any::TypeId;
+
+ pub const OBJECT: TypeId = TypeId::of::<Object>();
+ pub const STR: TypeId = TypeId::of::<&str>();
+ pub const U32: TypeId = TypeId::of::<u32>();
+ pub const U64: TypeId = TypeId::of::<u64>();
+}
+
#[derive(Default)]
pub struct Registry {
tags: BTreeMap<Tag, TagInfo>,
@@ -19,9 +29,31 @@ impl Registry {
}
self.tags.insert(tag, info);
}
+ pub fn info(&self, tag: Tag) -> Option<&TagInfo> {
+ self.tags.get(&tag)
+ }
}
pub struct TagInfo {
pub name: &'static str,
pub r#type: Option<TypeId>,
}
+
+#[macro_export]
+macro_rules! fields {
+ ($($id:ident: $type:ty = $tag:literal $name:literal;)*) => {
+ $(pub const $id: $crate::TypedTag<$type> = $crate::TypedTag($crate::Tag($tag), std::marker::PhantomData);)*
+ fn register_fields(reg: &mut $crate::Registry) {
+ $(reg.add($crate::Tag($tag), $crate::TagInfo { name: $name, r#type: Some(std::any::TypeId::of::<$type>()) });)*
+ }
+ };
+}
+#[macro_export]
+macro_rules! enums {
+ ($($id:ident = $tag:literal $name:literal;)*) => {
+ $(pub const $id: $crate::Tag = $crate::Tag($tag);)*
+ fn register_enums(reg: &mut $crate::Registry) {
+ $(reg.add($crate::Tag($tag), $crate::TagInfo { name: $name, r#type: None });)*
+ }
+ };
+}