hex
to rcore
This commit is contained in:
parent
cf2f3f8e01
commit
e317ce37c1
@ -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
29
src/rcore/to_hex.rs
Normal 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",
|
||||
);
|
||||
}
|
26
src/rstd.rs
26
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::<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)
|
||||
|
Loading…
Reference in New Issue
Block a user