Implementation of `azure_sdk_cosmos::traits::DatabaseClient` is not general enough

I am trying to figure out what to do about the following error:

error: implementation of `azure_sdk_cosmos::traits::DatabaseClient` is not general enough
  --> src/main.rs:20:10
   |
20 |           .and_then(mincase);
   |            ^^^^^^^^ implementation of `azure_sdk_cosmos::traits::DatabaseClient` is not general enough
   |
  ::: /home/yngling/.cargo/registry/src/github.com-1ecc6299db9ec823/azure_sdk_cosmos-0.100.2/src/traits.rs:32:1
   |
32 | / pub trait DatabaseClient<C>: HasCosmosClient<C>
33 | | where
34 | |     C: CosmosClient,
35 | | {
...  |
54 | |     }
55 | | }
   | |_- trait `azure_sdk_cosmos::traits::DatabaseClient` defined here
   |
   = note: `azure_sdk_cosmos::clients::database_struct::DatabaseStruct<'_, azure_sdk_cosmos::clients::cosmos_struct::CosmosStruct<'0, azure_sdk_cosmos::clients::cosmos_struct::DefaultCosmosUri>>` must implement `azure_sdk_cosmos::traits::DatabaseClient<azure_sdk_cosmos::clients::cosmos_struct::CosmosStruct<'1, azure_sdk_cosmos::clients::cosmos_struct::DefaultCosmosUri>>`, for any two lifetimes `'0` and `'1`...
   = note: ...but `azure_sdk_cosmos::traits::DatabaseClient<azure_sdk_cosmos::clients::cosmos_struct::CosmosStruct<'_, azure_sdk_cosmos::clients::cosmos_struct::DefaultCosmosUri>>` is actually implemented for the type `azure_sdk_cosmos::clients::database_struct::DatabaseStruct<'_, azure_sdk_cosmos::clients::cosmos_struct::CosmosStruct<'_, azure_sdk_cosmos::clients::cosmos_struct::DefaultCosmosUri>>`

error: aborting due to previous error

error: could not compile `mincase`.

I have made a fairly minimum reproducible case below.

Cargo.toml dependencies:

tokio = { version = "0.2", features = ["macros"] }
warp = "0.2"
serde = { version = "1.0", features = ["derive"] }
azure_sdk_cosmos = "0.100.2"
futures = "0.3"

main.rs:

use azure_sdk_cosmos::prelude::*;
use serde::{Deserialize, Serialize};
use warp::{reject, Filter};

#[derive(Serialize, Deserialize, Debug)]
struct MySampleStruct {
    id: String,
    name: String,
}

const COSMOS_MASTER_KEY: &str = "<cosmos master key here>";
const COSMOS_ACCOUNT: &str = "<cosmos account name here>";
const COSMOS_DATABASE: &str = "<cosmos database here>";

#[tokio::main]
async fn main() {
    let mincase = warp::path("mincase")
        .and(warp::path::end())
        .and(warp::get())
        .and_then(mincase);
    warp::serve(mincase).run(([127, 0, 0, 1], 3030)).await
}

pub async fn mincase() -> Result<impl warp::Reply, warp::Rejection> {
    let u = MySampleStruct {
        id: String::from("test"),
        name: String::from("test"),
    };

    // Create cosmos partition key.
    let mut pk = PartitionKeys::new();
    let pk = match pk.push(&u.name) {
        Ok(pk) => pk,
        Err(_) => {
            return Err(reject::reject());
        }
    };

    // Prepare document for inserting.
    let document_to_insert = Document::new(&u);

    let collection_name = "users";

    let authorization_token = match AuthorizationToken::new_master(COSMOS_MASTER_KEY) {
        Ok(t) => t,
        Err(_) => {
            return Err(reject::reject());
        }
    };

    let client = match ClientBuilder::new(COSMOS_ACCOUNT, authorization_token) {
        Ok(c) => c,
        Err(_) => {
            return Err(reject::reject());
        }
    };

    let client = client.with_database_client(COSMOS_DATABASE);
    let client = client.with_collection_client(collection_name);

    // Get user.
    let id = String::from("<document id here>");
    let partition_keys: PartitionKeys = (&id).into();

    let response = match client
        .with_document_client(&id, partition_keys.clone())
        .get_document()
        .execute::<MySampleStruct>()
        .await {
            Ok(d) => d,
            Err(err) => {
                return Err(reject::reject());
            }
    };

    Ok(warp::reply::json(&u))
}

Any help would be much appreciated!

Please post the full error.

I have updated my post!

Can you post the full error as printed by cargo check? This looks like pieces of text copied from IDE popups, which do not include the full error message.

That is indeed what I had done. I have updated my post again.

The error message being so poor is a bug in the compiler. I tried playing around with it a bit to see if I could find the actual cause, but I was not able to do so.

I understand, thank you so much for trying! Hopefully someone else have encountered this before and can lend a hand.

Well I have encountered it before. I was just not able to solve it.

:slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.