k8s_openapi/v1_35/apimachinery/pkg/apis/meta/v1/
server_address_by_client_cidr.rs

1// Generated from definition io.k8s.apimachinery.pkg.apis.meta.v1.ServerAddressByClientCIDR
2
3/// ServerAddressByClientCIDR helps the client to determine the server address that they should use, depending on the clientCIDR that they match.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ServerAddressByClientCIDR {
6    /// The CIDR with which clients can match their IP to figure out the server address that they should use.
7    pub client_cidr: std::string::String,
8
9    /// Address of this server, suitable for a client that matches the above CIDR. This can be a hostname, hostname:port, IP or IP:port.
10    pub server_address: std::string::String,
11}
12
13impl crate::DeepMerge for ServerAddressByClientCIDR {
14    fn merge_from(&mut self, other: Self) {
15        crate::DeepMerge::merge_from(&mut self.client_cidr, other.client_cidr);
16        crate::DeepMerge::merge_from(&mut self.server_address, other.server_address);
17    }
18}
19
20impl<'de> crate::serde::Deserialize<'de> for ServerAddressByClientCIDR {
21    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
22        #[allow(non_camel_case_types)]
23        enum Field {
24            Key_client_cidr,
25            Key_server_address,
26            Other,
27        }
28
29        impl<'de> crate::serde::Deserialize<'de> for Field {
30            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
31                struct Visitor;
32
33                impl crate::serde::de::Visitor<'_> for Visitor {
34                    type Value = Field;
35
36                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
37                        f.write_str("field identifier")
38                    }
39
40                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
41                        Ok(match v {
42                            "clientCIDR" => Field::Key_client_cidr,
43                            "serverAddress" => Field::Key_server_address,
44                            _ => Field::Other,
45                        })
46                    }
47                }
48
49                deserializer.deserialize_identifier(Visitor)
50            }
51        }
52
53        struct Visitor;
54
55        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
56            type Value = ServerAddressByClientCIDR;
57
58            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
59                f.write_str("ServerAddressByClientCIDR")
60            }
61
62            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
63                let mut value_client_cidr: Option<std::string::String> = None;
64                let mut value_server_address: Option<std::string::String> = None;
65
66                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
67                    match key {
68                        Field::Key_client_cidr => value_client_cidr = crate::serde::de::MapAccess::next_value(&mut map)?,
69                        Field::Key_server_address => value_server_address = crate::serde::de::MapAccess::next_value(&mut map)?,
70                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
71                    }
72                }
73
74                Ok(ServerAddressByClientCIDR {
75                    client_cidr: value_client_cidr.unwrap_or_default(),
76                    server_address: value_server_address.unwrap_or_default(),
77                })
78            }
79        }
80
81        deserializer.deserialize_struct(
82            "ServerAddressByClientCIDR",
83            &[
84                "clientCIDR",
85                "serverAddress",
86            ],
87            Visitor,
88        )
89    }
90}
91
92impl crate::serde::Serialize for ServerAddressByClientCIDR {
93    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
94        let mut state = serializer.serialize_struct(
95            "ServerAddressByClientCIDR",
96            2,
97        )?;
98        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "clientCIDR", &self.client_cidr)?;
99        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "serverAddress", &self.server_address)?;
100        crate::serde::ser::SerializeStruct::end(state)
101    }
102}
103
104#[cfg(feature = "schemars")]
105impl crate::schemars::JsonSchema for ServerAddressByClientCIDR {
106    fn schema_name() -> std::borrow::Cow<'static, str> {
107        "io.k8s.apimachinery.pkg.apis.meta.v1.ServerAddressByClientCIDR".into()
108    }
109
110    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
111        crate::schemars::json_schema!({
112            "description": "ServerAddressByClientCIDR helps the client to determine the server address that they should use, depending on the clientCIDR that they match.",
113            "type": "object",
114            "properties": {
115                "clientCIDR": {
116                    "description": "The CIDR with which clients can match their IP to figure out the server address that they should use.",
117                    "type": "string",
118                },
119                "serverAddress": {
120                    "description": "Address of this server, suitable for a client that matches the above CIDR. This can be a hostname, hostname:port, IP or IP:port.",
121                    "type": "string",
122                },
123            },
124            "required": [
125                "clientCIDR",
126                "serverAddress",
127            ],
128        })
129    }
130}