changeset 203:f1dd166ad40e

add multi-thread feature
author Daniel Boline <ddboline@gmail.com>
date Sun, 21 Feb 2021 16:36:46 -0500
parents a9052eb97e83
children 64b9c3214303
files async-google-apis-common/Cargo.toml async-google-apis-common/src/http.rs
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/async-google-apis-common/Cargo.toml	Fri Feb 19 18:51:28 2021 -0500
+++ b/async-google-apis-common/Cargo.toml	Sun Feb 21 16:36:46 2021 -0500
@@ -27,3 +27,7 @@
 tokio = { version = "1.0", features = ["fs"] }
 tokio-stream = "^0.1"
 yup-oauth2 = "~5"
+
+[features]
+default = []
+multi-thread = []
--- a/async-google-apis-common/src/http.rs	Fri Feb 19 18:51:28 2021 -0500
+++ b/async-google-apis-common/src/http.rs	Sun Feb 21 16:36:46 2021 -0500
@@ -2,6 +2,20 @@
 use anyhow::Context;
 use tokio::io::AsyncSeekExt;
 
+#[cfg(feature = "multi-thread")]
+pub trait AsyncWriteUnpin: tokio::io::AsyncWrite + std::marker::Unpin + Send + Sync {}
+
+#[cfg(feature = "multi-thread")]
+impl<T> AsyncWriteUnpin for T
+where T: tokio::io::AsyncWrite + std::marker::Unpin + Send + Sync {}
+
+#[cfg(not(feature = "multi-thread"))]
+pub trait AsyncWriteUnpin: tokio::io::AsyncWrite + std::marker::Unpin {}
+
+#[cfg(not(feature = "multi-thread"))]
+impl<T> AsyncWriteUnpin for T
+where T: tokio::io::AsyncWrite + std::marker::Unpin {}
+
 fn body_to_str(b: hyper::body::Bytes) -> String {
     String::from_utf8(b.to_vec()).unwrap_or("[UTF-8 decode failed]".into())
 }
@@ -181,7 +195,7 @@
     /// indicate that a download is expected.
     pub async fn do_it(
         &mut self,
-        dst: Option<&mut (dyn tokio::io::AsyncWrite + std::marker::Unpin + Send + Sync)>,
+        dst: Option<&mut (dyn AsyncWriteUnpin)>,
     ) -> Result<DownloadResult<Response>> {
         use std::str::FromStr;