changeset 37:77c979f1c242

Properly qualify enums in match{}
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 19 Oct 2020 10:24:43 +0200
parents 6f59ebfccb0e
children 34c794d4ca3a
files drive_example/src/drive_v3_types.rs generate/generate.py generate/templates.py
diffstat 3 files changed, 20 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/drive_example/src/drive_v3_types.rs	Mon Oct 19 10:21:24 2020 +0200
+++ b/drive_example/src/drive_v3_types.rs	Mon Oct 19 10:24:43 2020 +0200
@@ -1,4 +1,5 @@
 
+#![allow_unused]
 //! This file was generated by async-google-apis. (https://github.com/dermesser/async-google-apis)
 //!
 //! (c) 2020 Lewin Bormann <lbo@spheniscida.de>
@@ -71,14 +72,14 @@
 impl std::convert::AsRef<str> for DriveScopes {
     fn as_ref(&self) -> &'static str {
         match self {
-            Drive => "https://www.googleapis.com/auth/drive",
-            DriveAppdata => "https://www.googleapis.com/auth/drive.appdata",
-            DriveFile => "https://www.googleapis.com/auth/drive.file",
-            DriveMetadata => "https://www.googleapis.com/auth/drive.metadata",
-            DriveMetadataReadonly => "https://www.googleapis.com/auth/drive.metadata.readonly",
-            DrivePhotosReadonly => "https://www.googleapis.com/auth/drive.photos.readonly",
-            DriveReadonly => "https://www.googleapis.com/auth/drive.readonly",
-            DriveScripts => "https://www.googleapis.com/auth/drive.scripts",
+            DriveScopes::Drive => "https://www.googleapis.com/auth/drive",
+            DriveScopes::DriveAppdata => "https://www.googleapis.com/auth/drive.appdata",
+            DriveScopes::DriveFile => "https://www.googleapis.com/auth/drive.file",
+            DriveScopes::DriveMetadata => "https://www.googleapis.com/auth/drive.metadata",
+            DriveScopes::DriveMetadataReadonly => "https://www.googleapis.com/auth/drive.metadata.readonly",
+            DriveScopes::DrivePhotosReadonly => "https://www.googleapis.com/auth/drive.photos.readonly",
+            DriveScopes::DriveReadonly => "https://www.googleapis.com/auth/drive.readonly",
+            DriveScopes::DriveScripts => "https://www.googleapis.com/auth/drive.scripts",
         }
     }
 }
@@ -1054,7 +1055,7 @@
     #[serde(rename = "teamDriveId")]
     #[serde(skip_serializing_if = "Option::is_none")]
     pub team_drive_id: Option<String>,
-    /// A short-lived link to the file's thumbnail, if available. Typically lasts on the order of hours. Only populated when the requesting app can access the file's content. If the file isn't shared publicly, the URL returned in Files.thumbnailLink must be fetched using a credentialed request.
+    /// A short-lived link to the file's thumbnail, if available. Typically lasts on the order of hours. Only populated when the requesting app can access the file's content.
     #[serde(rename = "thumbnailLink")]
     #[serde(skip_serializing_if = "Option::is_none")]
     pub thumbnail_link: Option<String>,
@@ -3595,7 +3596,12 @@
         return Err(anyhow::Error::new(ApiError::HTTPError(resp.status())));
     }
     let resp_body = resp.into_body();
-    let write_result = resp_body.map(move |chunk| { dst.write(chunk?.as_ref()).map(|_| ()).map_err(Error::from) }).collect::<Vec<Result<()>>>().await;
+    let write_result = resp_body.map(move |chunk| {
+        dst.write(chunk?.as_ref())
+            .map(|_| ())
+            .map_err(Error::from)
+        })
+        .collect::<Vec<Result<()>>>().await;
     if let Some(e) = write_result.into_iter().find(|r| r.is_err()) {
         return e;
     }
--- a/generate/generate.py	Mon Oct 19 10:21:24 2020 +0200
+++ b/generate/generate.py	Mon Oct 19 10:24:43 2020 +0200
@@ -350,7 +350,7 @@
     for url, desc in scopes.items():
         rawname = url.split('/')[-1]
         fancy_name = ''.join([capitalize_first(p) for p in rawname.split('.')])
-        parameters['scopes'].append({'name': fancy_name, 'desc': desc.get('description', ''), 'url': url})
+        parameters['scopes'].append({'scope_name': fancy_name, 'desc': desc.get('description', ''), 'url': url})
     return chevron.render(OauthScopesType, parameters)
 
 
--- a/generate/templates.py	Mon Oct 19 10:21:24 2020 +0200
+++ b/generate/templates.py	Mon Oct 19 10:24:43 2020 +0200
@@ -1,5 +1,6 @@
 # General imports and error type.
 RustHeader = '''
+#![allow_unused]
 //! This file was generated by async-google-apis. (https://github.com/dermesser/async-google-apis)
 //!
 //! (c) 2020 Lewin Bormann <lbo@spheniscida.de>
@@ -44,7 +45,7 @@
     /// {{{desc}}}
     ///
     /// URL: {{{url}}}
-    {{{name}}},
+    {{{scope_name}}},
     {{/scopes}}
 }
 
@@ -52,7 +53,7 @@
     fn as_ref(&self) -> &'static str {
         match self {
             {{#scopes}}
-            {{{name}}} => "{{{url}}}",
+            {{{name}}}Scopes::{{{scope_name}}} => "{{{url}}}",
             {{/scopes}}
         }
     }