From 54e0d5cb906728ba301e309227ddf26c0782f66e Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 6 Jul 2022 18:46:03 -0700 Subject: [PATCH] impl Display for BlockState --- src/block.rs | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/block.rs b/src/block.rs index 7067138..f6d27a4 100644 --- a/src/block.rs +++ b/src/block.rs @@ -1,6 +1,6 @@ #![allow(clippy::all, missing_docs)] -use std::fmt; +use std::fmt::{self, Display}; use std::io::{Read, Write}; use anyhow::Context; @@ -11,30 +11,40 @@ use crate::protocol::{Decode, Encode, VarInt}; include!(concat!(env!("OUT_DIR"), "/block.rs")); impl fmt::Debug for BlockState { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt_block_state(*self, f) + } +} + +impl Display for BlockState { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let kind = self.to_kind(); + fmt_block_state(*self, f) + } +} - write!(f, "{}", kind.to_str())?; +fn fmt_block_state(bs: BlockState, f: &mut fmt::Formatter) -> fmt::Result { + let kind = bs.to_kind(); - let props = kind.props(); + write!(f, "{}", kind.to_str())?; - if !props.is_empty() { - let mut list = f.debug_list(); - for &p in kind.props() { - struct KeyVal<'a>(&'a str, &'a str); + let props = kind.props(); - impl<'a> fmt::Debug for KeyVal<'a> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}={}", self.0, self.1) - } + if !props.is_empty() { + let mut list = f.debug_list(); + for &p in kind.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(()) + + list.entry(&KeyVal(p.to_str(), bs.get(p).unwrap().to_str())); } + list.finish() + } else { + Ok(()) } }