impl Display for BlockState

This commit is contained in:
Ryan 2022-07-06 18:46:03 -07:00
parent 24cf864ed1
commit 54e0d5cb90

View file

@ -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,8 +11,19 @@ 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)
}
}
fn fmt_block_state(bs: BlockState, f: &mut fmt::Formatter) -> fmt::Result {
let kind = bs.to_kind();
write!(f, "{}", kind.to_str())?;
@ -29,14 +40,13 @@ impl fmt::Debug for BlockState {
}
}
list.entry(&KeyVal(p.to_str(), self.get(p).unwrap().to_str()));
list.entry(&KeyVal(p.to_str(), bs.get(p).unwrap().to_str()));
}
list.finish()
} else {
Ok(())
}
}
}
impl Encode for BlockState {
fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> {