The problem lies with url::form_urlencoded::Serializer which is not Send and there for cannot be carried across an await.
Using it within Tokio context throws an error on line /src/hyper/client.rs:117:13:
let response = self
.client
.request(request)
.await // <--------------------------- Throws here
.map_err(|err| Error::Send(err))?;
// ...
= help: the trait `Sync` is not implemented for `dyn for<'a> Fn(&'a s
note: future is not `Send` as this value is used across an await
--> /binance_spot_connector_rust-1.0.1/src/hyper/client.rs:117:13
|
68 | let mut serializer = url::form_urlencoded::Serializer::n...
| -------------- has type `form_urlencoded::Serializer<'_, std::string::String>` which is not `Send`
...
117 | .await
| ^^^^^^ await occurs here, with `mut serializer` maybe used later
...
122 | }
| - `mut serializer` is later dropped here
note: required by a bound in `tokio::spawn`
Solution
The fix is to put the serializer in a block so it drops before it could cross an await and it works like a charm :)
This PR enables binance_spot_connector with Hyper client to be used within async contexts and Tokio runtime.
Problem
Using hyper client within tokio::spawn throws an error.
The problem lies with
url::form_urlencoded::Serializer
which is not Send and there for cannot be carried across an await.Using it within Tokio context throws an error on line
/src/hyper/client.rs:117:13
:Solution
The fix is to put the serializer in a block so it drops before it could cross an await and it works like a charm :)