0

I am getting this error when I try using this function https://docs.rs/awc/2.0.3/awc/struct.Connector.html#method.rustls

async fn get_client_config() -> rustls::client::ClientConfig {
    let root_certs = rustls::RootCertStore::empty();
    rustls::ClientConfig::builder()
        .with_safe_defaults()
        .with_root_certificates(root_certs)
        .with_no_client_auth()
}

async fn get_client() -> Client {
    let client_config: rustls::client::ClientConfig = get_client_config().await;
    // Error in next line.
    let connector = Connector::new().rustls(client_config).finish(); 
    ClientBuilder::new().connector(connector).finish()
}
error[E0308]: mismatched types
  --> src/main.rs:31:59
   |
31 |     let connector = awc::Connector::new().rustls(Arc::new(client_config)).finish();
   |                                                           ^^^^^^^^^^^^^ expected struct `rustls::client::ClientConfig`, found struct `ClientConfig`
[dependencies]
awc = "2.0.3"
actix-web = "3.3.2"
futures-util = "0.3.17"
rustls = "0.20.1"                                                                                                                                    
actix-http = {version="2.2.1", features = ["rustls"]}
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
GrvTyagi
  • 4,231
  • 1
  • 33
  • 40

1 Answers1

1

awc 2.0.3 requires rustls 0.18.1, as you can see by following the link to the ClientConfig in the documentation. You are, however, trying to use rustls 0.20.1. From the compiler's point of view, these two versions are two distinct, totally independent crates, and the types inside them, even if they are defined exactly the same, are incompatible with each other.

The solution therefore is simple - change version of rustls in your Cargo.toml to the one accepted by awc, i.e. 0.18.1.

Cerberus
  • 8,879
  • 1
  • 25
  • 40