k8s_openapi/v1_30/api/core/v1/
grpc_action.rs

1// Generated from definition io.k8s.api.core.v1.GRPCAction
2
3#[derive(Clone, Debug, Default, PartialEq)]
4pub struct GRPCAction {
5    /// Port number of the gRPC service. Number must be in the range 1 to 65535.
6    pub port: i32,
7
8    /// Service is the name of the service to place in the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md).
9    ///
10    /// If this is not specified, the default behavior is defined by gRPC.
11    pub service: Option<std::string::String>,
12}
13
14impl crate::DeepMerge for GRPCAction {
15    fn merge_from(&mut self, other: Self) {
16        crate::DeepMerge::merge_from(&mut self.port, other.port);
17        crate::DeepMerge::merge_from(&mut self.service, other.service);
18    }
19}
20
21impl<'de> crate::serde::Deserialize<'de> for GRPCAction {
22    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
23        #[allow(non_camel_case_types)]
24        enum Field {
25            Key_port,
26            Key_service,
27            Other,
28        }
29
30        impl<'de> crate::serde::Deserialize<'de> for Field {
31            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32                struct Visitor;
33
34                impl crate::serde::de::Visitor<'_> for Visitor {
35                    type Value = Field;
36
37                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
38                        f.write_str("field identifier")
39                    }
40
41                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
42                        Ok(match v {
43                            "port" => Field::Key_port,
44                            "service" => Field::Key_service,
45                            _ => Field::Other,
46                        })
47                    }
48                }
49
50                deserializer.deserialize_identifier(Visitor)
51            }
52        }
53
54        struct Visitor;
55
56        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
57            type Value = GRPCAction;
58
59            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
60                f.write_str("GRPCAction")
61            }
62
63            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
64                let mut value_port: Option<i32> = None;
65                let mut value_service: Option<std::string::String> = None;
66
67                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
68                    match key {
69                        Field::Key_port => value_port = crate::serde::de::MapAccess::next_value(&mut map)?,
70                        Field::Key_service => value_service = crate::serde::de::MapAccess::next_value(&mut map)?,
71                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
72                    }
73                }
74
75                Ok(GRPCAction {
76                    port: value_port.unwrap_or_default(),
77                    service: value_service,
78                })
79            }
80        }
81
82        deserializer.deserialize_struct(
83            "GRPCAction",
84            &[
85                "port",
86                "service",
87            ],
88            Visitor,
89        )
90    }
91}
92
93impl crate::serde::Serialize for GRPCAction {
94    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
95        let mut state = serializer.serialize_struct(
96            "GRPCAction",
97            1 +
98            self.service.as_ref().map_or(0, |_| 1),
99        )?;
100        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", &self.port)?;
101        if let Some(value) = &self.service {
102            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "service", value)?;
103        }
104        crate::serde::ser::SerializeStruct::end(state)
105    }
106}
107
108#[cfg(feature = "schemars")]
109impl crate::schemars::JsonSchema for GRPCAction {
110    fn schema_name() -> std::borrow::Cow<'static, str> {
111        "io.k8s.api.core.v1.GRPCAction".into()
112    }
113
114    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
115        crate::schemars::json_schema!({
116            "type": "object",
117            "properties": {
118                "port": {
119                    "description": "Port number of the gRPC service. Number must be in the range 1 to 65535.",
120                    "type": "integer",
121                    "format": "int32",
122                },
123                "service": {
124                    "description": "Service is the name of the service to place in the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md).\n\nIf this is not specified, the default behavior is defined by gRPC.",
125                    "type": "string",
126                },
127            },
128            "required": [
129                "port",
130            ],
131        })
132    }
133}