drive_v3/objects/
label.rs

1use std::fmt;
2use serde::{Serialize, Deserialize};
3
4/// List of a file's labels.
5///
6/// # Note
7///
8/// All of the fields of [`LabelList`] are an [`Option<T>`] since the values
9/// that Google's API will return are dependent on the
10/// [`fields`](crate::resources::files::ListLabelsRequest::fields) requested, by
11/// default all fields will be requested but if you change this value only the
12/// specified fields will be [`Some<T>`], the rest will be [`None`].
13#[derive(Default, Debug, Clone, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct LabelList {
16    /// The page token for the next page of files.
17    ///
18    /// This will be absent if the end of the files list has been reached. If the token is rejected for any reason, it should be
19    /// discarded, and pagination should be restarted from the first page of results. The page token is typically valid for
20    /// several hours. However, if new items are added or removed, your expected results might differ.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub next_page_token: Option<String>,
23
24    /// Identifies what kind of resource this is. Value: the fixed string "drive#labelList".
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub kind: Option<String>,
27
28    /// The list of labels.
29    ///
30    /// If [`next_page_token`](LabelList::next_page_token) is populated, then this list may be incomplete and an additional page
31    /// of results should be fetched.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub labels: Option<Vec<Label>>,
34}
35
36impl fmt::Display for LabelList {
37    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
38        let json = serde_json::to_string_pretty(&self)
39            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
40
41        write!(f, "{}", json)
42    }
43}
44
45impl LabelList {
46    /// Creates a new, empty instance of this struct.
47    pub fn new() -> Self {
48        Self { ..Default::default() }
49    }
50}
51
52/// An overview of the labels on the file.
53#[derive(Default, Debug, Clone, Serialize, Deserialize)]
54#[serde(rename_all = "camelCase")]
55pub struct LabelInfo {
56    /// The set of labels on the file as requested by the label IDs in the includeLabels parameter.
57    ///
58    /// By default, no labels are returned.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub labels: Option<Vec<Label>>,
61}
62
63impl fmt::Display for LabelInfo {
64    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
65        let json = serde_json::to_string_pretty(&self)
66            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
67
68        write!(f, "{}", json)
69    }
70}
71
72impl LabelInfo {
73    /// Creates a new, empty instance of this struct.
74    pub fn new() -> Self {
75        Self { ..Default::default() }
76    }
77}
78
79/// Representation of label and label fields.
80#[derive(Default, Debug, Clone, Serialize, Deserialize)]
81#[serde(rename_all = "camelCase")]
82pub struct Label {
83    /// The ID of the label.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub id: Option<String>,
86
87    /// The revision ID of the label.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub revision_id: Option<String>,
90
91    /// This is always `drive#label`.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub kind: Option<String>,
94
95    /// A map of the fields on the label, keyed by the field's ID.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub fields: Option<serde_json::Map<String, serde_json::Value>>,
98}
99
100impl fmt::Display for Label {
101    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
102        let json = serde_json::to_string_pretty(&self)
103            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
104
105        write!(f, "{}", json)
106    }
107}
108
109impl Label {
110    /// Creates a new, empty instance of this struct.
111    pub fn new() -> Self {
112        Self { ..Default::default() }
113    }
114}
115
116/// existing label on a file, or remove a label from a file.
117#[derive(Default, Debug, Clone, Serialize, Deserialize)]
118#[serde(rename_all = "camelCase")]
119#[doc(hidden)]
120pub struct ModifyLabelsRequest {
121    /// The list of modifications to this label's fields.
122    #[serde(skip_serializing_if = "Option::is_none")]
123    pub label_modifications: Option<Vec<LabelModification>>,
124
125    /// This is always `drive#modifyLabelsRequest`.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub kind: Option<String>,
128}
129
130impl ModifyLabelsRequest {
131    /// Creates a new, empty instance of this struct.
132    pub fn new() -> Self {
133        Self { ..Default::default() }
134    }
135
136    /// Creates an instance of this struct from the given
137    /// [`field_modifications`](FieldModification).
138    pub fn from( label_modifications: &[LabelModification] ) -> Self {
139        Self {
140            label_modifications: Some( label_modifications.to_vec() ),
141            ..Default::default()
142        }
143    }
144}
145
146/// A modification to a label on a file.
147///
148/// A [`LabelModification`] can be used to apply a label to a file, update an
149/// existing label on a file, or remove a label from a file.
150#[derive(Default, Debug, Clone, Serialize, Deserialize)]
151#[serde(rename_all = "camelCase")]
152pub struct LabelModification {
153    /// The ID of the label to modify.
154    #[serde(skip_serializing_if = "Option::is_none")]
155    pub label_id: Option<String>,
156
157    /// The list of modifications to this label's fields.
158    #[serde(skip_serializing_if = "Option::is_none")]
159    pub field_modifications: Option<Vec<FieldModification>>,
160
161    /// If true, the label will be removed from the file.
162    #[serde(skip_serializing_if = "Option::is_none")]
163    pub remove_label: Option<bool>,
164
165    /// This is always `drive#labelModification`.
166    #[serde(skip_serializing_if = "Option::is_none")]
167    pub kind: Option<String>,
168}
169
170impl fmt::Display for LabelModification {
171    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
172        let json = serde_json::to_string_pretty(&self)
173            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
174
175        write!(f, "{}", json)
176    }
177}
178
179impl LabelModification {
180    /// Creates a new, empty instance of this struct.
181    pub fn new() -> Self {
182        Self { ..Default::default() }
183    }
184
185    /// Creates an instance of this struct from the given
186    /// [`field_modifications`](FieldModification).
187    pub fn from<T: AsRef<str>> ( id: T, field_modifications: &[FieldModification] ) -> Self {
188        Self {
189            label_id: Some( id.as_ref().to_string() ),
190            field_modifications: Some( field_modifications.to_vec() ),
191            ..Default::default()
192        }
193    }
194}
195
196/// A modification to a [`Label`](Label)'s field.
197#[derive(Default, Debug, Clone, Serialize, Deserialize)]
198#[serde(rename_all = "camelCase")]
199pub struct FieldModification {
200    /// The ID of the field to be modified.
201    #[serde(skip_serializing_if = "Option::is_none")]
202    pub field_id: Option<String>,
203
204    /// This is always `drive#labelFieldModification`.
205    #[serde(skip_serializing_if = "Option::is_none")]
206    pub kind: Option<String>,
207
208    /// Replaces the value of a date field with these new values.
209    ///
210    /// The string must be in the RFC 3339 full-date format: YYYY-MM-DD.
211    #[serde(skip_serializing_if = "Option::is_none")]
212    pub set_date_values: Option<Vec<String>>,
213
214    /// Sets the value of a `text` field.
215    #[serde(skip_serializing_if = "Option::is_none")]
216    pub set_text_values: Option<Vec<String>>,
217
218    /// Replaces a `selection` field with these new values.
219    #[serde(skip_serializing_if = "Option::is_none")]
220    pub set_selection_values: Option<Vec<String>>,
221
222    /// Replaces the value of an `integer` field with these new values.
223    #[serde(skip_serializing_if = "Option::is_none")]
224    pub set_integer_values: Option<Vec<String>>,
225
226    /// Replaces a `user` field with these new values.
227    ///
228    /// The values must be valid email addresses.
229    #[serde(skip_serializing_if = "Option::is_none")]
230    pub set_user_values: Option<Vec<String>>,
231
232    /// Unsets the values for this field.
233    #[serde(skip_serializing_if = "Option::is_none")]
234    pub unset_values: Option<bool>,
235}
236
237impl fmt::Display for FieldModification {
238    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
239        let json = serde_json::to_string_pretty(&self)
240            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
241
242        write!(f, "{}", json)
243    }
244}
245
246impl FieldModification {
247    /// Creates a new, empty instance of this struct.
248    pub fn new() -> Self {
249        Self { ..Default::default() }
250    }
251}