Add Debug impl to BlockState

This commit is contained in:
Ryan 2022-04-19 23:41:15 -07:00
parent 1a27cb92ce
commit f5f8264a70

View file

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