Skip to main content

dropbox_sdk/generated/types/
check.rs

1// DO NOT EDIT
2// This file was @generated by Stone
3
4#![allow(
5    clippy::too_many_arguments,
6    clippy::large_enum_variant,
7    clippy::result_large_err,
8    clippy::doc_markdown,
9    clippy::doc_lazy_continuation,
10)]
11
12/// Contains the arguments to be sent to the Dropbox servers.
13#[derive(Debug, Clone, PartialEq, Eq, Default)]
14#[non_exhaustive] // structs may have more fields added in the future.
15pub struct EchoArg {
16    /// The string that you'd like to be echoed back to you.
17    pub query: String,
18}
19
20impl EchoArg {
21    pub fn with_query(mut self, value: String) -> Self {
22        self.query = value;
23        self
24    }
25}
26
27const ECHO_ARG_FIELDS: &[&str] = &["query"];
28impl EchoArg {
29    // no _opt deserializer
30    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
31        mut map: V,
32    ) -> Result<EchoArg, V::Error> {
33        let mut field_query = None;
34        while let Some(key) = map.next_key::<&str>()? {
35            match key {
36                "query" => {
37                    if field_query.is_some() {
38                        return Err(::serde::de::Error::duplicate_field("query"));
39                    }
40                    field_query = Some(map.next_value()?);
41                }
42                _ => {
43                    // unknown field allowed and ignored
44                    map.next_value::<::serde_json::Value>()?;
45                }
46            }
47        }
48        let result = EchoArg {
49            query: field_query.unwrap_or_default(),
50        };
51        Ok(result)
52    }
53
54    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
55        &self,
56        s: &mut S::SerializeStruct,
57    ) -> Result<(), S::Error> {
58        use serde::ser::SerializeStruct;
59        if !self.query.is_empty() {
60            s.serialize_field("query", &self.query)?;
61        }
62        Ok(())
63    }
64}
65
66impl<'de> ::serde::de::Deserialize<'de> for EchoArg {
67    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
68        // struct deserializer
69        use serde::de::{MapAccess, Visitor};
70        struct StructVisitor;
71        impl<'de> Visitor<'de> for StructVisitor {
72            type Value = EchoArg;
73            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
74                f.write_str("a EchoArg struct")
75            }
76            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
77                EchoArg::internal_deserialize(map)
78            }
79        }
80        deserializer.deserialize_struct("EchoArg", ECHO_ARG_FIELDS, StructVisitor)
81    }
82}
83
84impl ::serde::ser::Serialize for EchoArg {
85    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
86        // struct serializer
87        use serde::ser::SerializeStruct;
88        let mut s = serializer.serialize_struct("EchoArg", 1)?;
89        self.internal_serialize::<S>(&mut s)?;
90        s.end()
91    }
92}
93
94/// EchoError contains the error returned from the Dropbox servers.
95#[derive(Debug, Clone, PartialEq, Eq)]
96#[non_exhaustive] // variants may be added in the future
97pub enum EchoError {
98    /// The request was successful.
99    UserRequested,
100    /// Catch-all used for unrecognized values returned from the server. Encountering this value
101    /// typically indicates that this SDK version is out of date.
102    Other,
103}
104
105impl<'de> ::serde::de::Deserialize<'de> for EchoError {
106    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
107        // union deserializer
108        use serde::de::{self, MapAccess, Visitor};
109        struct EnumVisitor;
110        impl<'de> Visitor<'de> for EnumVisitor {
111            type Value = EchoError;
112            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
113                f.write_str("a EchoError structure")
114            }
115            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
116                let tag: &str = match map.next_key()? {
117                    Some(".tag") => map.next_value()?,
118                    _ => return Err(de::Error::missing_field(".tag"))
119                };
120                let value = match tag {
121                    "user_requested" => EchoError::UserRequested,
122                    _ => EchoError::Other,
123                };
124                crate::eat_json_fields(&mut map)?;
125                Ok(value)
126            }
127        }
128        const VARIANTS: &[&str] = &["user_requested",
129                                    "other"];
130        deserializer.deserialize_struct("EchoError", VARIANTS, EnumVisitor)
131    }
132}
133
134impl ::serde::ser::Serialize for EchoError {
135    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
136        // union serializer
137        use serde::ser::SerializeStruct;
138        match self {
139            EchoError::UserRequested => {
140                // unit
141                let mut s = serializer.serialize_struct("EchoError", 1)?;
142                s.serialize_field(".tag", "user_requested")?;
143                s.end()
144            }
145            EchoError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
146        }
147    }
148}
149
150impl ::std::error::Error for EchoError {
151}
152
153impl ::std::fmt::Display for EchoError {
154    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
155        match self {
156            EchoError::UserRequested => f.write_str("The request was successful."),
157            _ => write!(f, "{:?}", *self),
158        }
159    }
160}
161
162/// EchoResult contains the result returned from the Dropbox servers.
163#[derive(Debug, Clone, PartialEq, Eq, Default)]
164#[non_exhaustive] // structs may have more fields added in the future.
165pub struct EchoResult {
166    /// If everything worked correctly, this would be the same as query.
167    pub result: String,
168}
169
170impl EchoResult {
171    pub fn with_result(mut self, value: String) -> Self {
172        self.result = value;
173        self
174    }
175}
176
177const ECHO_RESULT_FIELDS: &[&str] = &["result"];
178impl EchoResult {
179    // no _opt deserializer
180    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
181        mut map: V,
182    ) -> Result<EchoResult, V::Error> {
183        let mut field_result = None;
184        while let Some(key) = map.next_key::<&str>()? {
185            match key {
186                "result" => {
187                    if field_result.is_some() {
188                        return Err(::serde::de::Error::duplicate_field("result"));
189                    }
190                    field_result = Some(map.next_value()?);
191                }
192                _ => {
193                    // unknown field allowed and ignored
194                    map.next_value::<::serde_json::Value>()?;
195                }
196            }
197        }
198        let result = EchoResult {
199            result: field_result.unwrap_or_default(),
200        };
201        Ok(result)
202    }
203
204    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
205        &self,
206        s: &mut S::SerializeStruct,
207    ) -> Result<(), S::Error> {
208        use serde::ser::SerializeStruct;
209        if !self.result.is_empty() {
210            s.serialize_field("result", &self.result)?;
211        }
212        Ok(())
213    }
214}
215
216impl<'de> ::serde::de::Deserialize<'de> for EchoResult {
217    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
218        // struct deserializer
219        use serde::de::{MapAccess, Visitor};
220        struct StructVisitor;
221        impl<'de> Visitor<'de> for StructVisitor {
222            type Value = EchoResult;
223            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
224                f.write_str("a EchoResult struct")
225            }
226            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
227                EchoResult::internal_deserialize(map)
228            }
229        }
230        deserializer.deserialize_struct("EchoResult", ECHO_RESULT_FIELDS, StructVisitor)
231    }
232}
233
234impl ::serde::ser::Serialize for EchoResult {
235    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
236        // struct serializer
237        use serde::ser::SerializeStruct;
238        let mut s = serializer.serialize_struct("EchoResult", 1)?;
239        self.internal_serialize::<S>(&mut s)?;
240        s.end()
241    }
242}
243