From cfdee43a94e84109de46e316f1825e77c6e4337b Mon Sep 17 00:00:00 2001 From: Jean SIMARD Date: Sat, 21 Dec 2024 01:09:18 +0100 Subject: [PATCH] editoast: add a custom `Debug` implementation of `TrackRange` Signed-off-by: Jean SIMARD --- editoast/src/core/pathfinding.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/editoast/src/core/pathfinding.rs b/editoast/src/core/pathfinding.rs index 236494675d1..02f8a6afb58 100644 --- a/editoast/src/core/pathfinding.rs +++ b/editoast/src/core/pathfinding.rs @@ -157,7 +157,7 @@ pub enum PathfindingNotFound { /// An oriented range on a track section. /// `begin` is always less than `end`. -#[derive(Serialize, Deserialize, Clone, Debug, ToSchema, Hash, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Clone, ToSchema, Hash, PartialEq, Eq)] pub struct TrackRange { /// The track section identifier. #[schema(inline)] @@ -182,6 +182,17 @@ impl From for TrackRange { } } +impl std::fmt::Debug for TrackRange { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + write!(f, "'{}+", self.track_section)?; + if matches!(self.direction, Direction::StartToStop) { + write!(f, "{}-{}'", self.begin, self.end) + } else { + write!(f, "{}-{}'", self.end, self.begin) + } + } +} + #[cfg(test)] impl std::str::FromStr for TrackRange { type Err = String;