pub mod balance;
pub mod bounded;
pub mod errors;
pub mod primitives;
pub mod traits;
pub fn f64_approx_eq(a: f64, b: f64, epsilon: f64) -> bool {
float_cmp::ApproxEq::approx_eq(a, b, (epsilon, 2))
}
pub fn to_hex_shortened<const M: usize>(data: &impl AsRef<[u8]>) -> String {
let num_chars = M.max(4);
let data = data.as_ref();
if data.len() * 2 > M {
format!(
"{}..{}",
hex::encode(&data[0..(num_chars - 2) / 4]),
hex::encode(&data[data.len() - (num_chars - 2) / 4..])
)
} else {
hex::encode(data)
}
}
pub mod prelude {
pub use chrono::{DateTime, Utc};
pub use super::{
balance::*, bounded::BoundedVec, errors::GeneralError, f64_approx_eq, primitives::*,
to_hex_shortened, traits::*,
};
}
#[cfg(test)]
mod tests {
use hex_literal::hex;
use super::*;
#[test]
fn test_to_hex_shortened() {
assert_eq!(&to_hex_shortened::<0>(&hex!("deadbeefcafe")), "..");
assert_eq!(&to_hex_shortened::<1>(&hex!("deadbeefcafe")), "..");
assert_eq!(&to_hex_shortened::<2>(&hex!("deadbeefcafe")), "..");
assert_eq!(&to_hex_shortened::<3>(&hex!("deadbeefcafe")), "..");
assert_eq!(&to_hex_shortened::<4>(&hex!("deadbeefcafe")), "..");
assert_eq!(&to_hex_shortened::<5>(&hex!("deadbeefcafe")), "..");
assert_eq!(&to_hex_shortened::<6>(&hex!("deadbeefcafe")), "de..fe");
assert_eq!(&to_hex_shortened::<7>(&hex!("deadbeefcafe")), "de..fe");
assert_eq!(&to_hex_shortened::<8>(&hex!("deadbeefcafe")), "de..fe");
assert_eq!(&to_hex_shortened::<9>(&hex!("deadbeefcafe")), "de..fe");
assert_eq!(&to_hex_shortened::<10>(&hex!("deadbeefcafe")), "dead..cafe");
assert_eq!(&to_hex_shortened::<11>(&hex!("deadbeefcafe")), "dead..cafe");
assert_eq!(
&to_hex_shortened::<12>(&hex!("deadbeefcafe")),
"deadbeefcafe"
);
}
}