Skip to content

Commit

Permalink
feat: add ability to convert ContainerPort to u16 (#664)
Browse files Browse the repository at this point in the history
Add `as_u16` method to `ContainerPort`
  • Loading branch information
DDtKey authored Jun 16, 2024
1 parent 0afec13 commit c97f8be
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions testcontainers/src/core/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ impl TryFrom<PortMap> for Ports {
}
}

impl ContainerPort {
/// Returns the port number, regardless of the protocol.
pub fn as_u16(self) -> u16 {
match self {
ContainerPort::Tcp(port) | ContainerPort::Udp(port) | ContainerPort::Sctp(port) => port,
}
}
}

impl IntoContainerPort for u16 {
fn tcp(self) -> ContainerPort {
ContainerPort::Tcp(self)
Expand Down

0 comments on commit c97f8be

Please sign in to comment.