google_cloud_common/
model.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16
17#![allow(rustdoc::redundant_explicit_links)]
18#![allow(rustdoc::broken_intra_doc_links)]
19#![no_implicit_prelude]
20extern crate bytes;
21extern crate serde;
22extern crate serde_json;
23extern crate serde_with;
24extern crate std;
25extern crate wkt;
26
27/// Represents the metadata of the long-running operation.
28#[derive(Clone, Default, PartialEq)]
29#[non_exhaustive]
30pub struct OperationMetadata {
31    /// Output only. The time the operation was created.
32    pub create_time: std::option::Option<wkt::Timestamp>,
33
34    /// Output only. The time the operation finished running.
35    pub end_time: std::option::Option<wkt::Timestamp>,
36
37    /// Output only. Server-defined resource path for the target of the operation.
38    pub target: std::string::String,
39
40    /// Output only. Name of the verb executed by the operation.
41    pub verb: std::string::String,
42
43    /// Output only. Human-readable status of the operation, if any.
44    pub status_detail: std::string::String,
45
46    /// Output only. Identifies whether the user has requested cancellation
47    /// of the operation. Operations that have successfully been cancelled
48    /// have [Operation.error][] value with a [google.rpc.Status.code][] of 1,
49    /// corresponding to `Code.CANCELLED`.
50    pub cancel_requested: bool,
51
52    /// Output only. API version used to start the operation.
53    pub api_version: std::string::String,
54
55    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
56}
57
58impl OperationMetadata {
59    pub fn new() -> Self {
60        std::default::Default::default()
61    }
62
63    /// Sets the value of [create_time][crate::model::OperationMetadata::create_time].
64    pub fn set_create_time<T>(mut self, v: T) -> Self
65    where
66        T: std::convert::Into<wkt::Timestamp>,
67    {
68        self.create_time = std::option::Option::Some(v.into());
69        self
70    }
71
72    /// Sets or clears the value of [create_time][crate::model::OperationMetadata::create_time].
73    pub fn set_or_clear_create_time<T>(mut self, v: std::option::Option<T>) -> Self
74    where
75        T: std::convert::Into<wkt::Timestamp>,
76    {
77        self.create_time = v.map(|x| x.into());
78        self
79    }
80
81    /// Sets the value of [end_time][crate::model::OperationMetadata::end_time].
82    pub fn set_end_time<T>(mut self, v: T) -> Self
83    where
84        T: std::convert::Into<wkt::Timestamp>,
85    {
86        self.end_time = std::option::Option::Some(v.into());
87        self
88    }
89
90    /// Sets or clears the value of [end_time][crate::model::OperationMetadata::end_time].
91    pub fn set_or_clear_end_time<T>(mut self, v: std::option::Option<T>) -> Self
92    where
93        T: std::convert::Into<wkt::Timestamp>,
94    {
95        self.end_time = v.map(|x| x.into());
96        self
97    }
98
99    /// Sets the value of [target][crate::model::OperationMetadata::target].
100    pub fn set_target<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
101        self.target = v.into();
102        self
103    }
104
105    /// Sets the value of [verb][crate::model::OperationMetadata::verb].
106    pub fn set_verb<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
107        self.verb = v.into();
108        self
109    }
110
111    /// Sets the value of [status_detail][crate::model::OperationMetadata::status_detail].
112    pub fn set_status_detail<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
113        self.status_detail = v.into();
114        self
115    }
116
117    /// Sets the value of [cancel_requested][crate::model::OperationMetadata::cancel_requested].
118    pub fn set_cancel_requested<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
119        self.cancel_requested = v.into();
120        self
121    }
122
123    /// Sets the value of [api_version][crate::model::OperationMetadata::api_version].
124    pub fn set_api_version<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
125        self.api_version = v.into();
126        self
127    }
128}
129
130impl wkt::message::Message for OperationMetadata {
131    fn typename() -> &'static str {
132        "type.googleapis.com/google.cloud.common.OperationMetadata"
133    }
134}
135
136#[doc(hidden)]
137impl<'de> serde::de::Deserialize<'de> for OperationMetadata {
138    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
139    where
140        D: serde::Deserializer<'de>,
141    {
142        #[allow(non_camel_case_types)]
143        #[doc(hidden)]
144        #[derive(PartialEq, Eq, Hash)]
145        enum __FieldTag {
146            __create_time,
147            __end_time,
148            __target,
149            __verb,
150            __status_detail,
151            __cancel_requested,
152            __api_version,
153            Unknown(std::string::String),
154        }
155        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
156            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
157            where
158                D: serde::Deserializer<'de>,
159            {
160                struct Visitor;
161                impl<'de> serde::de::Visitor<'de> for Visitor {
162                    type Value = __FieldTag;
163                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
164                        formatter.write_str("a field name for OperationMetadata")
165                    }
166                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
167                    where
168                        E: serde::de::Error,
169                    {
170                        use std::result::Result::Ok;
171                        use std::string::ToString;
172                        match value {
173                            "createTime" => Ok(__FieldTag::__create_time),
174                            "create_time" => Ok(__FieldTag::__create_time),
175                            "endTime" => Ok(__FieldTag::__end_time),
176                            "end_time" => Ok(__FieldTag::__end_time),
177                            "target" => Ok(__FieldTag::__target),
178                            "verb" => Ok(__FieldTag::__verb),
179                            "statusDetail" => Ok(__FieldTag::__status_detail),
180                            "status_detail" => Ok(__FieldTag::__status_detail),
181                            "cancelRequested" => Ok(__FieldTag::__cancel_requested),
182                            "cancel_requested" => Ok(__FieldTag::__cancel_requested),
183                            "apiVersion" => Ok(__FieldTag::__api_version),
184                            "api_version" => Ok(__FieldTag::__api_version),
185                            _ => Ok(__FieldTag::Unknown(value.to_string())),
186                        }
187                    }
188                }
189                deserializer.deserialize_identifier(Visitor)
190            }
191        }
192        struct Visitor;
193        impl<'de> serde::de::Visitor<'de> for Visitor {
194            type Value = OperationMetadata;
195            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
196                formatter.write_str("struct OperationMetadata")
197            }
198            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
199            where
200                A: serde::de::MapAccess<'de>,
201            {
202                #[allow(unused_imports)]
203                use serde::de::Error;
204                use std::option::Option::Some;
205                let mut fields = std::collections::HashSet::new();
206                let mut result = Self::Value::new();
207                while let Some(tag) = map.next_key::<__FieldTag>()? {
208                    #[allow(clippy::match_single_binding)]
209                    match tag {
210                        __FieldTag::__create_time => {
211                            if !fields.insert(__FieldTag::__create_time) {
212                                return std::result::Result::Err(A::Error::duplicate_field(
213                                    "multiple values for create_time",
214                                ));
215                            }
216                            result.create_time =
217                                map.next_value::<std::option::Option<wkt::Timestamp>>()?;
218                        }
219                        __FieldTag::__end_time => {
220                            if !fields.insert(__FieldTag::__end_time) {
221                                return std::result::Result::Err(A::Error::duplicate_field(
222                                    "multiple values for end_time",
223                                ));
224                            }
225                            result.end_time =
226                                map.next_value::<std::option::Option<wkt::Timestamp>>()?;
227                        }
228                        __FieldTag::__target => {
229                            if !fields.insert(__FieldTag::__target) {
230                                return std::result::Result::Err(A::Error::duplicate_field(
231                                    "multiple values for target",
232                                ));
233                            }
234                            result.target = map
235                                .next_value::<std::option::Option<std::string::String>>()?
236                                .unwrap_or_default();
237                        }
238                        __FieldTag::__verb => {
239                            if !fields.insert(__FieldTag::__verb) {
240                                return std::result::Result::Err(A::Error::duplicate_field(
241                                    "multiple values for verb",
242                                ));
243                            }
244                            result.verb = map
245                                .next_value::<std::option::Option<std::string::String>>()?
246                                .unwrap_or_default();
247                        }
248                        __FieldTag::__status_detail => {
249                            if !fields.insert(__FieldTag::__status_detail) {
250                                return std::result::Result::Err(A::Error::duplicate_field(
251                                    "multiple values for status_detail",
252                                ));
253                            }
254                            result.status_detail = map
255                                .next_value::<std::option::Option<std::string::String>>()?
256                                .unwrap_or_default();
257                        }
258                        __FieldTag::__cancel_requested => {
259                            if !fields.insert(__FieldTag::__cancel_requested) {
260                                return std::result::Result::Err(A::Error::duplicate_field(
261                                    "multiple values for cancel_requested",
262                                ));
263                            }
264                            result.cancel_requested = map
265                                .next_value::<std::option::Option<bool>>()?
266                                .unwrap_or_default();
267                        }
268                        __FieldTag::__api_version => {
269                            if !fields.insert(__FieldTag::__api_version) {
270                                return std::result::Result::Err(A::Error::duplicate_field(
271                                    "multiple values for api_version",
272                                ));
273                            }
274                            result.api_version = map
275                                .next_value::<std::option::Option<std::string::String>>()?
276                                .unwrap_or_default();
277                        }
278                        __FieldTag::Unknown(key) => {
279                            let value = map.next_value::<serde_json::Value>()?;
280                            result._unknown_fields.insert(key, value);
281                        }
282                    }
283                }
284                std::result::Result::Ok(result)
285            }
286        }
287        deserializer.deserialize_any(Visitor)
288    }
289}
290
291#[doc(hidden)]
292impl serde::ser::Serialize for OperationMetadata {
293    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
294    where
295        S: serde::ser::Serializer,
296    {
297        use serde::ser::SerializeMap;
298        #[allow(unused_imports)]
299        use std::option::Option::Some;
300        let mut state = serializer.serialize_map(std::option::Option::None)?;
301        if self.create_time.is_some() {
302            state.serialize_entry("createTime", &self.create_time)?;
303        }
304        if self.end_time.is_some() {
305            state.serialize_entry("endTime", &self.end_time)?;
306        }
307        if !self.target.is_empty() {
308            state.serialize_entry("target", &self.target)?;
309        }
310        if !self.verb.is_empty() {
311            state.serialize_entry("verb", &self.verb)?;
312        }
313        if !self.status_detail.is_empty() {
314            state.serialize_entry("statusDetail", &self.status_detail)?;
315        }
316        if !wkt::internal::is_default(&self.cancel_requested) {
317            state.serialize_entry("cancelRequested", &self.cancel_requested)?;
318        }
319        if !self.api_version.is_empty() {
320            state.serialize_entry("apiVersion", &self.api_version)?;
321        }
322        if !self._unknown_fields.is_empty() {
323            for (key, value) in self._unknown_fields.iter() {
324                state.serialize_entry(key, &value)?;
325            }
326        }
327        state.end()
328    }
329}
330
331impl std::fmt::Debug for OperationMetadata {
332    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
333        let mut debug_struct = f.debug_struct("OperationMetadata");
334        debug_struct.field("create_time", &self.create_time);
335        debug_struct.field("end_time", &self.end_time);
336        debug_struct.field("target", &self.target);
337        debug_struct.field("verb", &self.verb);
338        debug_struct.field("status_detail", &self.status_detail);
339        debug_struct.field("cancel_requested", &self.cancel_requested);
340        debug_struct.field("api_version", &self.api_version);
341        if !self._unknown_fields.is_empty() {
342            debug_struct.field("_unknown_fields", &self._unknown_fields);
343        }
344        debug_struct.finish()
345    }
346}