Finding the exhaustive pattern in an enum match

I am trying to get results from a cosmos db database using the https://github.com/MindFlavor/AzureSDKForRust sdk.

I am able to see how many results are returned, but I do not understand how to write the enum in a way that lets me get the object.

Here is some sample code to illustrate the problem:

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 azure_sdk_cosmos::{Document, responses::QueryResult::Raw};
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 id = "<document id here>";

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

    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);

    let q = format!("SELECT * FROM objects o WHERE o.userId = '{}'", &id);
    let query_obj = Query::new(q.as_str());

    let respo: QueryDocumentsResponse<MySampleStruct> = match client
        .query_documents()
        .with_query(&query_obj)
        .with_partition_keys(pk)
        .execute()
        .await
    {
        Ok(res) => res,
        Err(_) => {
            return Err(reject::reject());
        }
    };

    for r in respo.results {
        match r {
            Raw(o) => {
                println!("ALPHA {}", o.name);
            },
        }
    }

    Ok("{}")
}

The code above gets a compiler error that non-exhaustive patterns: Document(_) not covered but I have not been able to see how to write it to get the MySampleStruct I specified. I am sure it is pretty simple, but Document(o) does not work, neither does &Document(DocumentQueryResult(o)).

Any help would be appreciated.

Looks like DocumentQueryResult hasn't been made fully public (expect it is a bug in lib.)

Probably should be here;
https://github.com/MindFlavor/AzureSDKForRust/blob/c8b523013d4367cbec43309cdb29a7afae624741/azure_sdk_cosmos/src/responses/mod.rs#L78

Thank you! I'll submit it as a bug with the author and see what he says. I was thinking it was something easy I had missed.

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.