radn-rs/src/rcore/to_hex.rs
timofey e317ce37c1
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.65) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.
hex to rcore
2023-09-03 20:30:08 +00:00

30 lines
566 B
Rust

use std::fmt::Display;
use super::*;
struct Hex<'a> {
point: &'a Hash,
}
impl Display for Hex<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for byte in self.point {
write!(f, "{byte:02x}")?
}
Ok(())
}
}
pub fn hex(point: &Hash) -> impl '_ + Display {
Hex { point }
}
#[cfg(test)]
#[test]
fn hex_test() {
assert_eq!(
hex(&(0..32).collect::<Vec<_>>().try_into().unwrap()).to_string(),
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
);
}