Skip to content

Commit

Permalink
feat: Add PortOffset::opposite
Browse files Browse the repository at this point in the history
  • Loading branch information
lmondada committed Jun 18, 2024
1 parent ab60561 commit f7b5628
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ impl PortOffset {
PortOffset::Outgoing(offset) => offset as usize,
}
}

/// Returns the opposite port offset.
///
/// This maps `PortOffset::Incoming(x)` to `PortOffset::Outgoing(x)` and
/// vice versa.
#[inline(always)]
pub fn opposite(&self) -> Self {
match self {
&PortOffset::Incoming(idx) => PortOffset::Outgoing(idx),
&PortOffset::Outgoing(idx) => PortOffset::Incoming(idx),
}
}
}

impl Default for PortOffset {
Expand Down

0 comments on commit f7b5628

Please sign in to comment.