Skip to content

Commit 2d07312

Browse files
committed
DeleteCollection::into_future
1 parent 89a1a8b commit 2d07312

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

sdk/data_cosmos/examples/create_delete_database.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
7070
println!("res == {:#?}", res);
7171
}
7272

73-
let delete_response = db_collection
74-
.delete_collection(Context::new(), DeleteCollectionOptions::new())
75-
.await?;
73+
let delete_response = db_collection.delete_collection().into_future().await?;
7674
println!("collection deleted: {:#?}", delete_response);
7775
}
7876

sdk/data_cosmos/examples/document_00.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
188188
.clone()
189189
.into_database_client(DATABASE.to_owned())
190190
.into_collection_client(COLLECTION.to_owned())
191-
.delete_collection(Context::new(), DeleteCollectionOptions::new())
191+
.delete_collection()
192+
.into_future()
192193
.await?;
193194
println!("collection deleted");
194195

sdk/data_cosmos/src/clients/collection_client.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,8 @@ impl CollectionClient {
6060
}
6161

6262
/// Delete a collection
63-
pub async fn delete_collection(
64-
&self,
65-
ctx: Context,
66-
options: DeleteCollectionOptions,
67-
) -> crate::Result<DeleteCollectionResponse> {
68-
let mut request = self.prepare_request_with_collection_name(http::Method::DELETE);
69-
70-
options.decorate_request(&mut request)?;
71-
72-
let response = self
73-
.pipeline()
74-
.send(ctx.clone().insert(ResourceType::Collections), &mut request)
75-
.await?;
76-
77-
Ok(DeleteCollectionResponse::try_from(response).await?)
63+
pub fn delete_collection(&self) -> DeleteCollectionBuilder {
64+
DeleteCollectionBuilder::new(self.clone())
7865
}
7966

8067
/// Replace a collection
@@ -163,7 +150,10 @@ impl CollectionClient {
163150
StoredProcedureClient::new(self, stored_procedure_name)
164151
}
165152

166-
fn prepare_request_with_collection_name(&self, http_method: http::Method) -> Request {
153+
pub(crate) fn prepare_request_with_collection_name(
154+
&self,
155+
http_method: http::Method,
156+
) -> Request {
167157
let path = &format!(
168158
"dbs/{}/colls/{}",
169159
self.database_client().database_name(),

sdk/data_cosmos/src/operations/delete_collection.rs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,60 @@
11
use crate::prelude::*;
22
use crate::{headers::from_headers::*, ResourceQuota};
33
use azure_core::headers::{content_type_from_headers, session_token_from_headers};
4-
use azure_core::{Request as HttpRequest, Response as HttpResponse};
4+
use azure_core::{Context, Response as HttpResponse};
55
use chrono::{DateTime, Utc};
66

77
#[derive(Debug, Clone)]
8-
pub struct DeleteCollectionOptions {
8+
pub struct DeleteCollectionBuilder {
9+
client: CollectionClient,
910
consistency_level: Option<ConsistencyLevel>,
11+
context: Context,
1012
}
1113

12-
impl DeleteCollectionOptions {
13-
pub fn new() -> Self {
14+
impl DeleteCollectionBuilder {
15+
pub fn new(client: CollectionClient) -> Self {
1416
Self {
17+
client,
1518
consistency_level: None,
19+
context: Context::new(),
1620
}
1721
}
1822

1923
setters! {
2024
consistency_level: ConsistencyLevel => Some(consistency_level),
2125
}
2226

23-
pub(crate) fn decorate_request(&self, request: &mut HttpRequest) -> crate::Result<()> {
24-
azure_core::headers::add_optional_header2(&self.consistency_level, request)?;
27+
pub fn into_future(self) -> DeleteCollection {
28+
Box::pin(async move {
29+
let mut request = self
30+
.client
31+
.prepare_request_with_collection_name(http::Method::DELETE);
2532

26-
Ok(())
33+
azure_core::headers::add_optional_header2(&self.consistency_level, &mut request)?;
34+
35+
let response = self
36+
.client
37+
.pipeline()
38+
.send(
39+
self.context.clone().insert(ResourceType::Collections),
40+
&mut request,
41+
)
42+
.await?;
43+
44+
Ok(DeleteCollectionResponse::try_from(response).await?)
45+
})
46+
}
47+
}
48+
49+
type DeleteCollection =
50+
futures::future::BoxFuture<'static, crate::Result<DeleteCollectionResponse>>;
51+
52+
#[cfg(feature = "into_future")]
53+
impl std::future::IntoFuture for DeleteCollectionBuilder {
54+
type Future = DeleteCollection;
55+
type Output = <DeleteCollection as std::future::Future>::Output;
56+
fn into_future(self) -> Self::Future {
57+
Self::into_future(self)
2758
}
2859
}
2960

0 commit comments

Comments
 (0)