diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-01-07 04:03:34 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-01-07 04:03:34 +0100 |
| commit | 7cc5fe5cd008072b99fc470b0ed730f7fa4e2881 (patch) | |
| tree | 5ae0e65497528342d3b21dd343ace364a61fb82c /common/object/src/inspect.rs | |
| parent | f932d4de439c6472d34ed4bbf530fca13b84d73a (diff) | |
| download | jellything-7cc5fe5cd008072b99fc470b0ed730f7fa4e2881.tar jellything-7cc5fe5cd008072b99fc470b0ed730f7fa4e2881.tar.bz2 jellything-7cc5fe5cd008072b99fc470b0ed730f7fa4e2881.tar.zst | |
debug inpect impl
Diffstat (limited to 'common/object/src/inspect.rs')
| -rw-r--r-- | common/object/src/inspect.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/common/object/src/inspect.rs b/common/object/src/inspect.rs new file mode 100644 index 0000000..871fae8 --- /dev/null +++ b/common/object/src/inspect.rs @@ -0,0 +1,38 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2026 metamuffin <metamuffin.org> +*/ + +use crate::{Object, Registry, types::*}; +use std::fmt::Debug; + +pub struct ObjectInpector<'a>(pub &'a Registry, pub Object<'a>); +impl Debug for ObjectInpector<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut s = f.debug_struct("Object"); + let mut nonexhaustive = false; + for (i, k) in self.1.keys().enumerate() { + let Some(info) = self.0.info(k) else { + nonexhaustive = true; + continue; + }; + let Some(ty) = info.r#type else { + nonexhaustive = true; + continue; + }; + match ty { + x if x == STR => s.field(info.name, &self.1.get_typed::<&str>(i).unwrap()), + x if x == OBJECT => s.field(info.name, &self.1.get_typed::<Object>(i).unwrap()), + x if x == U32 => s.field(info.name, &self.1.get_typed::<u32>(i).unwrap()), + x if x == U64 => s.field(info.name, &self.1.get_typed::<u64>(i).unwrap()), + _ => &mut s, + }; + } + if nonexhaustive { + s.finish_non_exhaustive() + } else { + s.finish() + } + } +} |