From df1913d8f3347847ef11e98b89087b8edd119796 Mon Sep 17 00:00:00 2001 From: tali Date: Sat, 15 Apr 2023 17:10:40 -0400 Subject: [PATCH] impl Display for Queue, impl Debug for Node --- fish/src/bot.rs | 2 +- fish/src/bot/node.rs | 13 +++++++++++++ mino/src/queue.rs | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fish/src/bot.rs b/fish/src/bot.rs index af8023f..b5709f9 100644 --- a/fish/src/bot.rs +++ b/fish/src/bot.rs @@ -130,7 +130,7 @@ impl SegmentedAStar { let rating = cand.rating(); if self.best().map_or(true, |n| rating < n.rating()) { tracing::debug!( - "update suggestion ({}): {rating}", + "update suggestion ({}): {cand:?}", self.best.map_or("1st", |_| "new") ); self.best = Some(cand.into()); diff --git a/fish/src/bot/node.rs b/fish/src/bot/node.rs index ad2bae1..462404d 100644 --- a/fish/src/bot/node.rs +++ b/fish/src/bot/node.rs @@ -148,6 +148,19 @@ impl Node { } } +impl core::fmt::Debug for Node { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "Node(rating={}", self.rating)?; + if let Some(pc) = self.root_placement() { + write!(f, ", root_placement={}", pc.ty)?; + } + if !self.queue().is_empty() { + write!(f, ", queue={}", self.queue())?; + } + write!(f, ")") + } +} + /// Represents an edge in the graph, pointing from a node to its parent. Particularly, /// contains the placement made in order to arrive at the child from the parent. struct Edge { diff --git a/mino/src/queue.rs b/mino/src/queue.rs index 6a6fd36..5850b88 100644 --- a/mino/src/queue.rs +++ b/mino/src/queue.rs @@ -64,6 +64,16 @@ impl<'a, T: Copy + Eq> Queue<'a, T> { } } +impl core::fmt::Display for Queue<'_, T> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self.hold { + Some(t) => write!(f, "[{t}]"), + None => write!(f, "[]"), + }?; + self.next.iter().try_for_each(|t| write!(f, "{t}")) + } +} + #[cfg(test)] mod test { use super::*;