}
}
-#[throws(fmt::Error)]
-fn fmt_hex(f: &mut Formatter, buf: &[u8]) {
- for v in buf { write!(f, "{:02x}", v)?; }
-}
-
-impl Debug for Hash {
- #[throws(fmt::Error)]
- fn fmt(&self, f: &mut Formatter) { fmt_hex(f, &self.0)? }
-}
+format_by_fmt_hex!{Debug, for Hash, .0}
impl Display for Hash {
#[throws(fmt::Error)]
fn fmt(&self, f: &mut Formatter) {
pub use crate::dbgc;
pub use crate::{deref_to_field, deref_to_field_mut};
pub use crate::ensure_eq;
+pub use crate::format_by_fmt_hex;
pub use crate::matches_doesnot;
pub use crate::trace_dbg;
pub use crate::{want, wantok, wants, want_let, want_failed_internal};
self.raw.get_or_extend_with(i.index(), f)
}
}
+
+
+#[throws(fmt::Error)]
+pub fn fmt_hex(f: &mut Formatter, buf: &[u8]) {
+ for v in buf { write!(f, "{:02x}", v)?; }
+}
+
+#[macro_export]
+macro_rules! format_by_fmt_hex {
+ ($trait:ty, for $self:ty, . $($memb:tt)+) => {
+ impl $trait for $self {
+ #[throws(fmt::Error)]
+ fn fmt(&self, f: &mut Formatter) {
+ fmt_hex(f, &self . $($memb)+)?
+ }
+ }
+ }
+}