Skip to content

Commit a47bca1

Browse files
authored
fix: Improve NodeId's debug representation (#547)
1 parent 3aab4ac commit a47bca1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

common/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ pub enum TextDecoration {
625625
pub type NodeIdContent = u64;
626626

627627
/// The stable identity of a [`Node`], unique within the node's tree.
628-
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
628+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
629629
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
630630
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
631631
#[repr(transparent)]
@@ -645,6 +645,12 @@ impl From<NodeId> for NodeIdContent {
645645
}
646646
}
647647

648+
impl fmt::Debug for NodeId {
649+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
650+
write!(f, "#{}", self.0)
651+
}
652+
}
653+
648654
/// Defines a custom action for a UI element.
649655
///
650656
/// For example, a list UI can allow a user to reorder items in the list by dragging the

consumer/src/tree.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ struct InternalChanges {
2828
impl State {
2929
fn validate_global(&self) {
3030
if !self.nodes.contains_key(&self.data.root) {
31-
panic!("Root id #{} is not in the node list", self.data.root.0);
31+
panic!("Root ID {:?} is not in the node list", self.data.root);
3232
}
3333
if !self.nodes.contains_key(&self.focus) {
34-
panic!("Focused id #{} is not in the node list", self.focus.0);
34+
panic!("Focused ID {:?} is not in the node list", self.focus);
3535
}
3636
}
3737

@@ -78,8 +78,8 @@ impl State {
7878
for (child_index, child_id) in node_data.children().iter().enumerate() {
7979
if seen_child_ids.contains(child_id) {
8080
panic!(
81-
"Node #{} of TreeUpdate includes duplicate child #{};",
82-
node_id.0, child_id.0
81+
"Node {:?} of TreeUpdate includes duplicate child {:?};",
82+
node_id, child_id
8383
);
8484
}
8585
unreachable.remove(child_id);
@@ -139,7 +139,7 @@ impl State {
139139
panic!("TreeUpdate includes {} nodes which are neither in the current tree nor a child of another node from the update: {}", pending_nodes.len(), ShortNodeList(&pending_nodes));
140140
}
141141
if !pending_children.is_empty() {
142-
panic!("TreeUpdate's nodes include {} children ids which are neither in the current tree nor the id of another node from the update: {}", pending_children.len(), ShortNodeList(&pending_children));
142+
panic!("TreeUpdate's nodes include {} children ids which are neither in the current tree nor the ID of another node from the update: {}", pending_children.len(), ShortNodeList(&pending_children));
143143
}
144144

145145
self.focus = update.focus;
@@ -361,7 +361,7 @@ impl<T> fmt::Display for ShortNodeList<'_, T> {
361361
if i != 0 {
362362
write!(f, ", ")?;
363363
}
364-
write!(f, "#{}", id.0)?;
364+
write!(f, "{:?}", id)?;
365365
}
366366
if iter.next().is_some() {
367367
write!(f, " ...")?;

0 commit comments

Comments
 (0)