From e317ce37c17be5ac761226465946d6b53acfd65e Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 3 Sep 2023 20:30:08 +0000 Subject: [PATCH] `hex` to `rcore` --- src/rcore.rs | 2 ++ src/rcore/to_hex.rs | 29 +++++++++++++++++++++++++++++ src/rstd.rs | 26 -------------------------- 3 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 src/rcore/to_hex.rs diff --git a/src/rcore.rs b/src/rcore.rs index a33bab2..80dae13 100644 --- a/src/rcore.rs +++ b/src/rcore.rs @@ -18,6 +18,7 @@ mod regular; mod resolution; mod resolver_origin; mod singular; +mod to_hex; mod topology; use std::{error::Error, sync::Arc}; @@ -43,6 +44,7 @@ pub use self::resolution::{ ResolutionFailure, ResolutionResult, Resolver, ResolverMap, }; pub use self::singular::SingularResolution; +pub use self::to_hex::hex; pub use self::topology::MentionableTop; /// Helper alias for [`WeakFunctor::F`] of [`FunctorContext::T`]. diff --git a/src/rcore/to_hex.rs b/src/rcore/to_hex.rs new file mode 100644 index 0000000..5c40a37 --- /dev/null +++ b/src/rcore/to_hex.rs @@ -0,0 +1,29 @@ +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::>().try_into().unwrap()).to_string(), + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + ); +} diff --git a/src/rstd.rs b/src/rstd.rs index 2b160b8..c883981 100644 --- a/src/rstd.rs +++ b/src/rstd.rs @@ -22,32 +22,6 @@ use crate::func::*; use crate::mode::*; use crate::rcore::*; -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(crate) fn hex(point: &Hash) -> impl '_ + Display { - Hex { point } -} - -#[cfg(test)] -#[test] -fn hex_test() { - assert_eq!( - hex(&(0..32).collect::>().try_into().unwrap()).to_string(), - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - ); -} - impl Display for Address { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}@{}", hex(&self.point), self.index)