openshift_openapi/v4_5/api/route/v1/
route_target_reference.rs

1// Generated from definition com.github.openshift.api.route.v1.RouteTargetReference
2
3/// RouteTargetReference specifies the target that resolve into endpoints. Only the 'Service' kind is allowed. Use 'weight' field to emphasize one over others.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct RouteTargetReference {
6    /// The kind of target that the route is referring to. Currently, only 'Service' is allowed
7    pub kind: String,
8
9    /// name of the service/target that is being referred to. e.g. name of the service
10    pub name: String,
11
12    /// weight as an integer between 0 and 256, default 1, that specifies the target's relative weight against other target reference objects. 0 suppresses requests to this backend.
13    pub weight: i32,
14}
15
16impl<'de> serde::Deserialize<'de> for RouteTargetReference {
17    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
18        #[allow(non_camel_case_types)]
19        enum Field {
20            Key_kind,
21            Key_name,
22            Key_weight,
23            Other,
24        }
25
26        impl<'de> serde::Deserialize<'de> for Field {
27            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
28                struct Visitor;
29
30                impl<'de> serde::de::Visitor<'de> for Visitor {
31                    type Value = Field;
32
33                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34                        f.write_str("field identifier")
35                    }
36
37                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
38                        Ok(match v {
39                            "kind" => Field::Key_kind,
40                            "name" => Field::Key_name,
41                            "weight" => Field::Key_weight,
42                            _ => Field::Other,
43                        })
44                    }
45                }
46
47                deserializer.deserialize_identifier(Visitor)
48            }
49        }
50
51        struct Visitor;
52
53        impl<'de> serde::de::Visitor<'de> for Visitor {
54            type Value = RouteTargetReference;
55
56            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57                f.write_str("RouteTargetReference")
58            }
59
60            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
61                let mut value_kind: Option<String> = None;
62                let mut value_name: Option<String> = None;
63                let mut value_weight: Option<i32> = None;
64
65                while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
66                    match key {
67                        Field::Key_kind => value_kind = Some(serde::de::MapAccess::next_value(&mut map)?),
68                        Field::Key_name => value_name = Some(serde::de::MapAccess::next_value(&mut map)?),
69                        Field::Key_weight => value_weight = Some(serde::de::MapAccess::next_value(&mut map)?),
70                        Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
71                    }
72                }
73
74                Ok(RouteTargetReference {
75                    kind: value_kind.ok_or_else(|| serde::de::Error::missing_field("kind"))?,
76                    name: value_name.ok_or_else(|| serde::de::Error::missing_field("name"))?,
77                    weight: value_weight.ok_or_else(|| serde::de::Error::missing_field("weight"))?,
78                })
79            }
80        }
81
82        deserializer.deserialize_struct(
83            "RouteTargetReference",
84            &[
85                "kind",
86                "name",
87                "weight",
88            ],
89            Visitor,
90        )
91    }
92}
93
94impl serde::Serialize for RouteTargetReference {
95    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
96        let mut state = serializer.serialize_struct(
97            "RouteTargetReference",
98            3,
99        )?;
100        serde::ser::SerializeStruct::serialize_field(&mut state, "kind", &self.kind)?;
101        serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
102        serde::ser::SerializeStruct::serialize_field(&mut state, "weight", &self.weight)?;
103        serde::ser::SerializeStruct::end(state)
104    }
105}