changeset 204:64b9c3214303

add multi-thread feature to generator
author Daniel Boline <ddboline@gmail.com>
date Sun, 21 Feb 2021 16:44:34 -0500
parents f1dd166ad40e
children ec212287e4a3
files generate/templates.py
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/generate/templates.py	Sun Feb 21 16:36:46 2021 -0500
+++ b/generate/templates.py	Sun Feb 21 16:44:34 2021 -0500
@@ -19,6 +19,21 @@
 //! THIS FILE HAS BEEN GENERATED -- SAVE ANY MODIFICATIONS BEFORE REPLACING.
 
 use async_google_apis_common::*;
+
+#[cfg(feature = "multi-thread")]
+pub trait DerefAuth: std::ops::Deref<Target=Authenticator> + Send + Sync {}
+
+#[cfg(feature = "multi-thread")]
+impl<T> DerefAuth for T
+where T: std::ops::Deref<Target=Authenticator> + Send + Sync {}
+
+#[cfg(not(feature = "multi-thread"))]
+pub trait DerefAuth: std::ops::Deref<Target=Authenticator> {}
+
+#[cfg(not(feature = "multi-thread"))]
+impl<T> DerefAuth for T
+where T: std::ops::Deref<Target=Authenticator> {}
+
 '''
 
 # Dict contents --
@@ -128,7 +143,7 @@
 pub struct {{{service}}}Service {
     client: TlsClient,
     {{#wants_auth}}
-    authenticator: Box<dyn 'static + std::ops::Deref<Target=Authenticator>>,
+    authenticator: Box<dyn 'static + DerefAuth>,
     scopes: Vec<String>,
     {{/wants_auth}}
 
@@ -141,7 +156,7 @@
     /// into an `Rc`: `new(client.clone(), Rc::new(authenticator))`.
     /// This way, one authenticator can be shared among several services.
     pub fn new
-    {{#wants_auth}}<A: 'static + std::ops::Deref<Target=Authenticator>>
+    {{#wants_auth}}<A: 'static + DerefAuth>
     {{/wants_auth}}(client: TlsClient{{#wants_auth}}, auth: A{{/wants_auth}}) -> {{service}}Service {
         {{{service}}}Service { client: client
             {{#wants_auth}}, authenticator: Box::new(auth), scopes: vec![]{{/wants_auth}},