feat: adopt IntoFuture trait and update dependencies

This commit is contained in:
Robert Pack 2022-12-05 10:22:51 +01:00
Родитель 3683ecaa51
Коммит ef0d7d62ec
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: AF0F16B1EB819B7D
7 изменённых файлов: 69 добавлений и 60 удалений

Просмотреть файл

@ -5,6 +5,7 @@ description = "Rust wrappers around Microsoft Azure REST APIs - Azure Data Explo
readme = "README.md"
license = "MIT"
edition = "2021"
rust-version = "1.64"
repository = "https://github.com/azure/azure-sdk-for-rust"
homepage = "https://github.com/azure/azure-sdk-for-rust"
documentation = "https://docs.rs/azure_kusto_data"
@ -12,12 +13,12 @@ keywords = ["sdk", "azure", "kusto", "azure-data-explorer"]
categories = ["api-bindings"]
[dependencies]
arrow = { version = "20.0.0", optional = true }
azure_core = { version = "0.4.0", features = [
arrow = { version = "26.0.0", optional = true }
azure_core = { version = "0.7.0", features = [
"enable_reqwest",
"enable_reqwest_gzip",
] }
azure_identity = { version = "0.5.0" }
azure_identity = { version = "0.8.0" }
async-trait = "0.1.57"
async-convert = "1.0.0"
bytes = "1.2.1"
@ -27,7 +28,7 @@ serde = { version = "1.0.143", features = ["derive"] }
serde_json = "1.0.81"
serde_with = { version = "2.0.0", features = ["json"] }
thiserror = "1.0.32"
hashbrown = "0.12.3"
hashbrown = "0.13"
regex = "1.6.0"
time = { version = "0.3.13", features = [
"serde",
@ -36,17 +37,17 @@ time = { version = "0.3.13", features = [
"macros",
"serde-well-known",
] }
derive_builder = "0.11.2"
derive_builder = "0.12"
once_cell = "1.13.0"
[dev-dependencies]
arrow = { version = "20.0.0", features = ["prettyprint"] }
arrow = { version = "26.0.0", features = ["prettyprint"] }
dotenv = "0.15.0"
env_logger = "0.9"
env_logger = "0.10"
tokio = { version = "1.20.1", features = ["macros"] }
oauth2 = "4.2.3"
criterion = "0.3.6"
clap = { version = "3.2.17", features = ["derive", "env"] }
criterion = "0.4"
clap = { version = "4", features = ["derive", "env"] }
[features]
default = ["arrow"]

Просмотреть файл

@ -33,7 +33,6 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let response = client
.execute_command(database, query)
.into_future()
.await
.expect("Failed to execute query");

Просмотреть файл

@ -57,7 +57,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
.expect("Failed to create request options"),
),
)
.into_future()
.await
.unwrap();

Просмотреть файл

@ -994,6 +994,7 @@ impl ConnectionString {
client_secret,
client_authority,
} => Arc::new(ClientSecretCredential::new(
azure_core::new_http_client(),
client_authority,
client_id,
client_secret,
@ -1007,7 +1008,7 @@ impl ConnectionString {
Arc::new(ImdsManagedIdentityCredential::default())
}
}
ConnectionStringAuth::AzureCli => Arc::new(AzureCliCredential),
ConnectionStringAuth::AzureCli => Arc::new(AzureCliCredential::new()),
ConnectionStringAuth::DeviceCode { .. } => unimplemented!(),
ConnectionStringAuth::InteractiveLogin => unimplemented!(),
ConnectionStringAuth::TokenCredential { credential } => credential.clone(),

Просмотреть файл

@ -19,6 +19,7 @@ use futures::{Stream, TryFutureExt, TryStreamExt};
use http::header::CONNECTION;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::future::IntoFuture;
use std::io::ErrorKind;
type QueryRun = BoxFuture<'static, Result<KustoResponse>>;
@ -48,29 +49,7 @@ pub struct V1QueryRunner(pub QueryRunner);
pub struct V2QueryRunner(pub QueryRunner);
impl V1QueryRunner {
pub fn into_future(self) -> V1QueryRun {
Box::pin(async {
let V1QueryRunner(query_runner) = self;
let future = query_runner.into_future().await?;
Ok(
std::convert::TryInto::try_into(future).expect("Unexpected conversion error from KustoResponse to KustoResponseDataSetV1 - please report this issue to the Kusto team")
)
})
}
}
impl V2QueryRunner {
pub fn into_future(self) -> V2QueryRun {
Box::pin(async {
let V2QueryRunner(query_runner) = self;
let future = query_runner.into_future().await?;
Ok(
std::convert::TryInto::try_into(future).expect("Unexpected conversion error from KustoResponse to KustoResponseDataSetV2 - please report this issue to the Kusto team")
)
})
}
pub async fn into_stream(self) -> Result<impl Stream<Item = Result<V2QueryResult>>> {
let V2QueryRunner(query_runner) = self;
query_runner.into_stream().await
@ -78,27 +57,6 @@ impl V2QueryRunner {
}
impl QueryRunner {
pub fn into_future(self) -> QueryRun {
let this = self.clone();
Box::pin(async move {
let response = self.into_response().await?;
Ok(match this.kind {
QueryKind::Management => {
<KustoResponseDataSetV1 as TryFrom<HttpResponse>>::try_from(response)
.map_ok(KustoResponse::V1)
.await?
}
QueryKind::Query => {
<KustoResponseDataSetV2 as TryFrom<HttpResponse>>::try_from(response)
.map_ok(KustoResponse::V2)
.await?
}
})
})
}
async fn into_response(self) -> Result<Response> {
let url = match self.kind {
QueryKind::Management => self.client.management_url(),
@ -156,6 +114,62 @@ impl QueryRunner {
}
}
impl IntoFuture for V1QueryRunner {
type IntoFuture = V1QueryRun;
type Output = Result<KustoResponseDataSetV1>;
fn into_future(self) -> V1QueryRun {
Box::pin(async {
let V1QueryRunner(query_runner) = self;
let future = query_runner.into_future().await?;
Ok(
std::convert::TryInto::try_into(future).expect("Unexpected conversion error from KustoResponse to KustoResponseDataSetV1 - please report this issue to the Kusto team")
)
})
}
}
impl IntoFuture for V2QueryRunner {
type IntoFuture = V2QueryRun;
type Output = Result<KustoResponseDataSetV2>;
fn into_future(self) -> V2QueryRun {
Box::pin(async {
let V2QueryRunner(query_runner) = self;
let future = query_runner.into_future().await?;
Ok(
std::convert::TryInto::try_into(future).expect("Unexpected conversion error from KustoResponse to KustoResponseDataSetV2 - please report this issue to the Kusto team")
)
})
}
}
impl IntoFuture for QueryRunner {
type IntoFuture = QueryRun;
type Output = Result<KustoResponse>;
fn into_future(self) -> QueryRun {
let this = self.clone();
Box::pin(async move {
let response = self.into_response().await?;
Ok(match this.kind {
QueryKind::Management => {
<KustoResponseDataSetV1 as TryFrom<HttpResponse>>::try_from(response)
.map_ok(KustoResponse::V1)
.await?
}
QueryKind::Query => {
<KustoResponseDataSetV2 as TryFrom<HttpResponse>>::try_from(response)
.map_ok(KustoResponse::V2)
.await?
}
})
})
}
}
/// A Kusto query response.
#[derive(Debug, Clone)]
pub enum KustoResponse {

Просмотреть файл

@ -43,7 +43,6 @@ async fn arrow_roundtrip() {
";
let response = client
.execute_query(database, query)
.into_future()
.await
.expect("Failed to run query");
let batches = response

Просмотреть файл

@ -7,7 +7,6 @@ async fn create_query_delete_table() {
let query = ".set KustoRsTest <| let text=\"Hello, World!\"; print str=text";
let response = client
.execute_command(database.clone(), query)
.into_future()
.await
.expect("Failed to run query");
@ -16,7 +15,6 @@ async fn create_query_delete_table() {
let query = ".show tables | where TableName == \"KustoRsTest\"";
let response = client
.execute_command(database.clone(), query)
.into_future()
.await
.expect("Failed to run query");
@ -25,7 +23,6 @@ async fn create_query_delete_table() {
let query = "KustoRsTest | take 1";
let response = client
.execute_query(database.clone(), query)
.into_future()
.await
.expect("Failed to run query");
@ -35,7 +32,6 @@ async fn create_query_delete_table() {
let query = ".drop table KustoRsTest | where TableName == \"KustoRsTest\"";
let response = client
.execute_command(database.clone(), query)
.into_future()
.await
.expect("Failed to run query");