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 udp(name: impl ToString, port: i32) -> Self
where
Self: std::marker::Sized,
{
Self::new(name, port).protocol("UDP")
}
fn sctp(name: impl ToString, port: i32) -> Self
where
Self: std::marker::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 }
}
}
pub trait ToIntOrString {
fn to_int_or_string(self) -> intstr::IntOrString;
}
impl ToIntOrString for i32 {
fn to_int_or_string(self) -> intstr::IntOrString {
intstr::IntOrString::Int(self)
}
}
impl ToIntOrString for String {
fn to_int_or_string(self) -> intstr::IntOrString {
intstr::IntOrString::String(self)
}
}
impl ToIntOrString for &str {
fn to_int_or_string(self) -> intstr::IntOrString {
intstr::IntOrString::String(self.to_string())
}
}