k8s_openapi_ext/ext/
service_port.rs1use super::*;
2
3pub trait ServicePortExt {
4 fn new(name: impl ToString, port: impl Into<i32>) -> Self;
7
8 fn target_port(self, port: impl ToIntOrString) -> Self;
11
12 fn protocol(self, protocol: impl ToString) -> Self;
15
16 fn tcp(name: impl ToString, port: impl Into<i32>) -> Self
19 where
20 Self: Sized,
21 {
22 Self::new(name, port).protocol("TCP")
23 }
24
25 fn udp(name: impl ToString, port: impl Into<i32>) -> Self
28 where
29 Self: Sized,
30 {
31 Self::new(name, port).protocol("UDP")
32 }
33
34 fn sctp(name: impl ToString, port: impl Into<i32>) -> Self
37 where
38 Self: Sized,
39 {
40 Self::new(name, port).protocol("SCTP")
41 }
42}
43
44impl ServicePortExt for corev1::ServicePort {
45 fn new(name: impl ToString, port: impl Into<i32>) -> Self {
46 let name = Some(name.to_string());
47 let port = port.into();
48 Self {
49 name,
50 port,
51 ..default()
56 }
57 }
58
59 fn target_port(self, port: impl ToIntOrString) -> Self {
60 let target_port = Some(port.to_int_or_string());
61 Self {
62 target_port,
63 ..self
64 }
65 }
66
67 fn protocol(self, protocol: impl ToString) -> Self {
68 let protocol = Some(protocol.to_string());
69 Self { protocol, ..self }
70 }
71}