aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/object/src/inspect.rs24
-rw-r--r--common/object/src/lib.rs3
-rw-r--r--common/object/src/tests.rs19
3 files changed, 38 insertions, 8 deletions
diff --git a/common/object/src/inspect.rs b/common/object/src/inspect.rs
index 871fae8..21648bd 100644
--- a/common/object/src/inspect.rs
+++ b/common/object/src/inspect.rs
@@ -4,11 +4,12 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use crate::{Object, Registry, types::*};
-use std::fmt::Debug;
+use crate::{Object, Registry, Tag, TypedTag, types::*};
+use std::{any::type_name, fmt::Debug};
-pub struct ObjectInpector<'a>(pub &'a Registry, pub Object<'a>);
-impl Debug for ObjectInpector<'_> {
+pub struct Inspector<'a, T>(pub &'a Registry, pub T);
+
+impl Debug for Inspector<'_, Object<'_>> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut s = f.debug_struct("Object");
let mut nonexhaustive = false;
@@ -36,3 +37,18 @@ impl Debug for ObjectInpector<'_> {
}
}
}
+
+impl<T> Debug for Inspector<'_, TypedTag<T>> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let name = self.0.info(self.1.0).map(|t| t.name).unwrap_or("unknown");
+ f.debug_tuple(&format!("TypedTag<{}>", type_name::<T>()))
+ .field(&name)
+ .finish()
+ }
+}
+impl Debug for Inspector<'_, Tag> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let name = self.0.info(self.1).map(|t| t.name).unwrap_or("unknown");
+ f.debug_tuple("Tag").field(&name).finish()
+ }
+}
diff --git a/common/object/src/lib.rs b/common/object/src/lib.rs
index 59a758f..02b2293 100644
--- a/common/object/src/lib.rs
+++ b/common/object/src/lib.rs
@@ -7,7 +7,7 @@
mod buffer;
pub mod inspect;
-pub mod path;
+mod path;
mod registry;
#[cfg(test)]
mod tests;
@@ -15,6 +15,7 @@ mod value;
pub use buffer::*;
pub use registry::*;
pub use value::*;
+pub use path::*;
use std::marker::PhantomData;
diff --git a/common/object/src/tests.rs b/common/object/src/tests.rs
index 6ffa9e5..59e6d8c 100644
--- a/common/object/src/tests.rs
+++ b/common/object/src/tests.rs
@@ -4,7 +4,7 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use crate::{ObjectBuffer, Registry, fields, inspect::ObjectInpector};
+use crate::{ObjectBuffer, Registry, fields, inspect::Inspector};
use std::sync::LazyLock;
pub static TAGREG: LazyLock<Registry> = LazyLock::new(|| {
@@ -76,8 +76,21 @@ fn insert() {
}
#[test]
-fn inspect() {
+fn inspect_object() {
let bob = test_object();
- eprintln!("{:#?}", ObjectInpector(&TAGREG, bob.as_object()));
+ eprintln!("{:#?}", Inspector(&TAGREG, bob.as_object()));
// panic!()
}
+
+#[test]
+fn inspect_tag() {
+ assert_eq!(
+ format!("{:?}", Inspector(&TAGREG, FRIEND)),
+ "TypedTag<&str>(\"friend\")"
+ );
+ assert_eq!(
+ format!("{:?}", Inspector(&TAGREG, AGE)),
+ "TypedTag<u32>(\"age\")"
+ );
+ assert_eq!(format!("{:?}", Inspector(&TAGREG, NAME.0)), "Tag(\"name\")");
+}