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::*;