ferristseng / rust-ipfs-api

IPFS HTTP client in Rust
Apache License 2.0
246 stars 68 forks source link

type inside `async` block must be known in this context #97

Closed jrouaix closed 2 years ago

jrouaix commented 2 years ago

Hello, I tried my best to use the crate as shown in the examples, but I struggle on an error : type inside async block must be known in this context

[dev-dependencies]
ipfs-api-backend-hyper = { version = "0.3", features = ["with-hyper-tls"] }
use ipfs_api::{IpfsApi, IpfsClient};
use ipfs_api_backend_hyper as ipfs_api;
use std::io::Cursor;

#[tokio::test]
async fn test() -> anyhow::Result<()> {
    let client = IpfsClient::default();
    let data = Cursor::new("Hello World!");

    match client.add(data).await {
        Ok(res) => println!("{}", res.hash),
        Err(e) => eprintln!("error adding file: {}", e),
    }
    Ok(())
}
error[E0698]: type inside `async` block must be known in this context
  --> app/tests/ipfs_tests.rs:7:18
   |
7  |     let client = IpfsClient::default();
   |                  ^^^^^^^^^^ cannot infer type for type parameter `C` declared on the struct `HyperBackend`
   |
note: the type is part of the `async` block because of this `await`
  --> app/tests/ipfs_tests.rs:10:27
   |
10 |     match client.add(data).await {
   |                           ^^^^^^

error[E0283]: type annotations needed
 --> app/tests/ipfs_tests.rs:7:18
  |
7 |     let client = IpfsClient::default();
  |                  ^^^^^^^^^^^^^^^^^^^ cannot infer type for struct `IpfsClient<_>`
  |
  = note: multiple `impl`s satisfying `IpfsClient<_>: Default` found in the `ipfs_api_backend_hyper` crate:
          - impl Default for IpfsClient;
          - impl Default for IpfsClient<hyper_tls::client::HttpsConnector<hyper::client::connect::http::HttpConnector>>;

do you have any idea about what's going on ?

jrouaix commented 2 years ago

Well, it seems I just had to write IpfsClient::<HttpConnector<GaiResolver>>::default(); with use hyper::client::{connect::dns::GaiResolver, HttpConnector}; And add the hyper = "0.14" in the toml and it's compiling just fine. But I still wondering why all your examples are working without all this.