impl fmt::Display for Sha256 for Logging

This commit is contained in:
CodeSteak 2019-06-03 19:05:55 +02:00
parent 189b1955d7
commit b2ba9a9ba4
2 changed files with 13 additions and 7 deletions

View File

@ -1,5 +1,7 @@
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;
#[derive(Clone, Debug, PartialOrd, Ord, Deserialize, Serialize, Eq, Hash, PartialEq)]
pub struct Sha256(#[serde(serialize_with = "as_hex", deserialize_with = "from_hex")] pub [u8; 32]);
@ -49,6 +51,15 @@ impl Sha256 {
}
}
impl fmt::Display for Sha256 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for digit in self.0.iter() {
write!(f, "{:02X}", digit)?
}
Ok(())
}
}
fn as_hex<S>(hash: &[u8; 32], serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,

View File

@ -99,12 +99,7 @@ impl ProtocolHandler for ServerState {
let data = data_store.read_texture_file_by_hash(&hash);
println!(
"{}: Texture File: '{:?}' found: {}",
con,
&hash,
data.is_ok()
);
println!("{}: Texture File: '{}' found: {}", con, &hash, data.is_ok());
Ok(data?)
}
@ -123,7 +118,7 @@ impl ProtocolHandler for ServerState {
let preview = data_store.get_texture_preview(&hash, format);
println!(
"{}: Texture Preview: '{:?}' found: {}",
"{}: Texture Preview: '{}' found: {}",
con,
&hash,
preview.is_ok()