openshift_openapi/v4_5/api/apps/v1/
lifecycle_hook.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct LifecycleHook {
6 pub exec_new_pod: Option<crate::api::apps::v1::ExecNewPodHook>,
8
9 pub failure_policy: String,
11
12 pub tag_images: Option<Vec<crate::api::apps::v1::TagImageHook>>,
14}
15
16impl<'de> serde::Deserialize<'de> for LifecycleHook {
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_exec_new_pod,
21 Key_failure_policy,
22 Key_tag_images,
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 "execNewPod" => Field::Key_exec_new_pod,
40 "failurePolicy" => Field::Key_failure_policy,
41 "tagImages" => Field::Key_tag_images,
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 = LifecycleHook;
55
56 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 f.write_str("LifecycleHook")
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_exec_new_pod: Option<crate::api::apps::v1::ExecNewPodHook> = None;
62 let mut value_failure_policy: Option<String> = None;
63 let mut value_tag_images: Option<Vec<crate::api::apps::v1::TagImageHook>> = None;
64
65 while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
66 match key {
67 Field::Key_exec_new_pod => value_exec_new_pod = serde::de::MapAccess::next_value(&mut map)?,
68 Field::Key_failure_policy => value_failure_policy = Some(serde::de::MapAccess::next_value(&mut map)?),
69 Field::Key_tag_images => value_tag_images = 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(LifecycleHook {
75 exec_new_pod: value_exec_new_pod,
76 failure_policy: value_failure_policy.ok_or_else(|| serde::de::Error::missing_field("failurePolicy"))?,
77 tag_images: value_tag_images,
78 })
79 }
80 }
81
82 deserializer.deserialize_struct(
83 "LifecycleHook",
84 &[
85 "execNewPod",
86 "failurePolicy",
87 "tagImages",
88 ],
89 Visitor,
90 )
91 }
92}
93
94impl serde::Serialize for LifecycleHook {
95 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
96 let mut state = serializer.serialize_struct(
97 "LifecycleHook",
98 1 +
99 self.exec_new_pod.as_ref().map_or(0, |_| 1) +
100 self.tag_images.as_ref().map_or(0, |_| 1),
101 )?;
102 if let Some(value) = &self.exec_new_pod {
103 serde::ser::SerializeStruct::serialize_field(&mut state, "execNewPod", value)?;
104 }
105 serde::ser::SerializeStruct::serialize_field(&mut state, "failurePolicy", &self.failure_policy)?;
106 if let Some(value) = &self.tag_images {
107 serde::ser::SerializeStruct::serialize_field(&mut state, "tagImages", value)?;
108 }
109 serde::ser::SerializeStruct::end(state)
110 }
111}