qdrant-client 1.20.0

Rust client for Qdrant Vector Search Engine
Documentation
//! Regenerates `src/serverless/grpc.rs` from `proto/serverless_collections.proto`.
//!
//! Run with: `cargo test --test serverless_protos -- --ignored --nocapture`

use std::fs;
use std::path::Path;
use std::time::SystemTime;

fn timestamp(f: impl AsRef<Path>) -> SystemTime {
    fs::metadata(f).unwrap().modified().unwrap()
}

const GRPC_OUTPUT_FILE: &str = "src/serverless/grpc.rs";
const PROTO_FILE: &str = "proto/serverless_collections.proto";

#[test]
#[ignore = "run explicitly to regenerate serverless gRPC stubs"]
fn regenerate_serverless_protos() {
    tonic_prost_build::configure()
        .build_server(false)
        .build_client(true)
        .out_dir("src/serverless/")
        .compile_protos(&[PROTO_FILE], &["proto"])
        .expect("failed to compile serverless protos");

    // prost writes `<package>.rs` based on the last package component for nested packages,
    // or a path. Rename/normalize to grpc.rs.
    // package qdrant.serverless -> typically produces qdrant.serverless.rs or nested.
    // With tonic-prost-build, the file is named after the proto package path.
    let candidates = [
        "src/serverless/qdrant.serverless.rs",
        "src/serverless/serverless.rs",
        "src/serverless/qdrant.rs",
    ];
    let generated = candidates
        .into_iter()
        .find(|p| Path::new(p).exists())
        .expect("expected generated serverless stub file");

    if generated != GRPC_OUTPUT_FILE {
        fs::rename(generated, GRPC_OUTPUT_FILE).expect("rename generated file");
    }

    // Keep generated types crate-private; the public surface is models + client.
    let contents = fs::read_to_string(GRPC_OUTPUT_FILE).unwrap();
    let banner = "// @generated by tonic-prost-build. DO NOT EDIT.\n// Regenerate: cargo test --test serverless_protos -- --ignored --nocapture\n";
    if !contents.starts_with("// @generated") {
        fs::write(GRPC_OUTPUT_FILE, format!("{banner}{contents}")).unwrap();
    }
    eprintln!("Wrote {GRPC_OUTPUT_FILE}");
}

#[test]
fn serverless_protos_are_fresh() {
    if !Path::new(GRPC_OUTPUT_FILE).exists() {
        panic!("{GRPC_OUTPUT_FILE} missing; run: cargo test --test serverless_protos -- --ignored");
    }
    let out_time = timestamp(GRPC_OUTPUT_FILE);
    let proto_time = timestamp(PROTO_FILE);
    assert!(
        proto_time <= out_time,
        "{PROTO_FILE} is newer than {GRPC_OUTPUT_FILE}; regenerate with: cargo test --test serverless_protos -- --ignored"
    );
}