# HG changeset patch # User Augie Fackler # Date 2022-05-05 18:47:26 # Node ID 34decbaf4da31e1340ba75b1a4f3eae7a260d55f # Parent 3f86ee422095bd86cbfd3cc5601b46360dcb278a node: manually implement Debug I got too irritated today with the default Debug implementation of hg::revlog::Node while playing with a new parser. This isn't quite what I wanted, but it wasn't much code and it at least gives you output that's easy to visually compare to a node.hex()ed identifier from the Python side of things. Sadly, this doesn't influence the output in lldb or the VSCode debugger extension that uses lldb under the covers, but it at least means debug prints are a little more useful. Differential Revision: https://phab.mercurial-scm.org/D12608 diff --git a/rust/hg-core/src/revlog/node.rs b/rust/hg-core/src/revlog/node.rs --- a/rust/hg-core/src/revlog/node.rs +++ b/rust/hg-core/src/revlog/node.rs @@ -53,12 +53,21 @@ type NodeData = [u8; NODE_BYTES_LENGTH]; /// the size or return an error at runtime. /// /// [`nybbles_len`]: #method.nybbles_len -#[derive(Copy, Clone, Debug, PartialEq, BytesCast, derive_more::From)] +#[derive(Copy, Clone, PartialEq, BytesCast, derive_more::From)] #[repr(transparent)] pub struct Node { data: NodeData, } +impl fmt::Debug for Node { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let n = format!("{:x?}", self.data); + // We're using debug_tuple because it makes the output a little + // more compact without losing data. + f.debug_tuple("Node").field(&n).finish() + } +} + /// The node value for NULL_REVISION pub const NULL_NODE: Node = Node { data: [0; NODE_BYTES_LENGTH],