k8s_openapi/v1_35/api/core/v1/
container_user.rs

1// Generated from definition io.k8s.api.core.v1.ContainerUser
2
3/// ContainerUser represents user identity information
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ContainerUser {
6    /// Linux holds user identity information initially attached to the first process of the containers in Linux. Note that the actual running identity can be changed if the process has enough privilege to do so.
7    pub linux: Option<crate::api::core::v1::LinuxContainerUser>,
8}
9
10impl crate::DeepMerge for ContainerUser {
11    fn merge_from(&mut self, other: Self) {
12        crate::DeepMerge::merge_from(&mut self.linux, other.linux);
13    }
14}
15
16impl<'de> crate::serde::Deserialize<'de> for ContainerUser {
17    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
18        #[allow(non_camel_case_types)]
19        enum Field {
20            Key_linux,
21            Other,
22        }
23
24        impl<'de> crate::serde::Deserialize<'de> for Field {
25            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26                struct Visitor;
27
28                impl crate::serde::de::Visitor<'_> for Visitor {
29                    type Value = Field;
30
31                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
32                        f.write_str("field identifier")
33                    }
34
35                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
36                        Ok(match v {
37                            "linux" => Field::Key_linux,
38                            _ => Field::Other,
39                        })
40                    }
41                }
42
43                deserializer.deserialize_identifier(Visitor)
44            }
45        }
46
47        struct Visitor;
48
49        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
50            type Value = ContainerUser;
51
52            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
53                f.write_str("ContainerUser")
54            }
55
56            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
57                let mut value_linux: Option<crate::api::core::v1::LinuxContainerUser> = None;
58
59                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
60                    match key {
61                        Field::Key_linux => value_linux = crate::serde::de::MapAccess::next_value(&mut map)?,
62                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
63                    }
64                }
65
66                Ok(ContainerUser {
67                    linux: value_linux,
68                })
69            }
70        }
71
72        deserializer.deserialize_struct(
73            "ContainerUser",
74            &[
75                "linux",
76            ],
77            Visitor,
78        )
79    }
80}
81
82impl crate::serde::Serialize for ContainerUser {
83    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
84        let mut state = serializer.serialize_struct(
85            "ContainerUser",
86            self.linux.as_ref().map_or(0, |_| 1),
87        )?;
88        if let Some(value) = &self.linux {
89            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "linux", value)?;
90        }
91        crate::serde::ser::SerializeStruct::end(state)
92    }
93}
94
95#[cfg(feature = "schemars")]
96impl crate::schemars::JsonSchema for ContainerUser {
97    fn schema_name() -> std::borrow::Cow<'static, str> {
98        "io.k8s.api.core.v1.ContainerUser".into()
99    }
100
101    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
102        crate::schemars::json_schema!({
103            "description": "ContainerUser represents user identity information",
104            "type": "object",
105            "properties": {
106                "linux": ({
107                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::LinuxContainerUser>();
108                    schema_obj.ensure_object().insert("description".into(), "Linux holds user identity information initially attached to the first process of the containers in Linux. Note that the actual running identity can be changed if the process has enough privilege to do so.".into());
109                    schema_obj
110                }),
111            },
112        })
113    }
114}