use super::*;
pub trait ServicePortExt {
fn new(name: impl ToString, port: i32) -> Self;
fn target_port(self, port: impl ToIntOrString) -> Self;
fn protocol(self, protocol: impl ToString) -> Self;
fn tcp(name: impl ToString, port: i32) -> Self
where
Self: Sized,
{
Self::new(name, port).protocol("TCP")
}
fn udp(name: impl ToString, port: i32) -> Self
where
Self: Sized,
{
Self::new(name, port).protocol("UDP")
}
fn sctp(name: impl ToString, port: i32) -> Self
where
Self: Sized,
{
Self::new(name, port).protocol("SCTP")
}
}
impl ServicePortExt for corev1::ServicePort {
fn new(name: impl ToString, port: i32) -> Self {
let name = Some(name.to_string());
Self {
name,
port,
..default()
}
}
fn target_port(self, port: impl ToIntOrString) -> Self {
let target_port = Some(port.to_int_or_string());
Self {
target_port,
..self
}
}
fn protocol(self, protocol: impl ToString) -> Self {
let protocol = Some(protocol.to_string());
Self { protocol, ..self }
}
}