hex to rcore
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.

This commit is contained in:
AF 2023-09-03 20:30:08 +00:00
parent cf2f3f8e01
commit e317ce37c1
3 changed files with 31 additions and 26 deletions

View File

@ -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`].

29
src/rcore/to_hex.rs Normal file
View File

@ -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::<Vec<_>>().try_into().unwrap()).to_string(),
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
);
}

View File

@ -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::<Vec<_>>().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)