From f5f8264a70cf3be4e24a7c1f365f0e0a457f58e7 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 19 Apr 2022 23:41:15 -0700 Subject: [PATCH] Add Debug impl to BlockState --- src/block.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/block.rs b/src/block.rs index 59e7b05..a7cc560 100644 --- a/src/block.rs +++ b/src/block.rs @@ -1,7 +1,37 @@ #![allow(clippy::all)] +use std::fmt; + include!(concat!(env!("OUT_DIR"), "/block.rs")); +impl fmt::Debug for BlockState { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let typ = self.to_type(); + + write!(f, "{}", typ.to_str())?; + + let props = typ.props(); + + if !props.is_empty() { + let mut list = f.debug_list(); + for &p in typ.props() { + struct KeyVal<'a>(&'a str, &'a str); + + impl<'a> fmt::Debug for KeyVal<'a> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}={}", self.0, self.1) + } + } + + list.entry(&KeyVal(p.to_str(), self.get(p).unwrap().to_str())); + } + list.finish() + } else { + Ok(()) + } + } +} + #[cfg(test)] mod tests { use super::*;