Skip to content

Commit

Permalink
Show ranges when debugging port indices (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q authored Jun 13, 2023
1 parent 8bd5a61 commit e440f6f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/portgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,8 @@ mod debug {

impl<'a> std::fmt::Debug for NodeDebug<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let inputs: Vec<_> = self.0.inputs(self.1).collect();
let outputs: Vec<_> = self.0.outputs(self.1).collect();
let inputs = PortRangeDebug(self.0.inputs(self.1).as_range());
let outputs = PortRangeDebug(self.0.outputs(self.1).as_range());

f.debug_struct("Node")
.field("inputs", &inputs)
Expand All @@ -1316,6 +1316,25 @@ mod debug {
}
}

pub struct PortRangeDebug(pub Range<usize>);

impl std::fmt::Debug for PortRangeDebug {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.0.is_empty() {
write!(fmt, "[]")?;
} else if self.0.len() == 1 {
write!(fmt, "[")?;
PortIndex::new(self.0.start).fmt(fmt)?;
write!(fmt, "]")?;
} else {
PortIndex::new(self.0.start).fmt(fmt)?;
write!(fmt, "..")?;
PortIndex::new(self.0.end).fmt(fmt)?;
}
Ok(())
}
}

pub struct PortsDebug<'a>(pub &'a PortGraph);

impl<'a> std::fmt::Debug for PortsDebug<'a> {
Expand Down

0 comments on commit e440f6f

Please sign in to comment.