Skip to content

Commit

Permalink
editoast: add a custom Debug implementation of TrackRange
Browse files Browse the repository at this point in the history
Signed-off-by: Jean SIMARD <[email protected]>
  • Loading branch information
woshilapin committed Dec 21, 2024
1 parent 663e8e6 commit cfdee43
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion editoast/src/core/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -182,6 +182,17 @@ impl From<editoast_schemas::infra::DirectionalTrackRange> 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;
Expand Down

0 comments on commit cfdee43

Please sign in to comment.