Skip to content

Commit 866ffd4

Browse files
committed
DeletePermission::into_future
1 parent 63dfdf2 commit 866ffd4

File tree

4 files changed

+47
-31
lines changed

4 files changed

+47
-31
lines changed

sdk/data_cosmos/examples/permission_00.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
138138
);
139139

140140
let delete_permission_response = permission_client
141-
.delete_permission(
142-
Context::new(),
143-
DeletePermissionOptions::new().consistency_level(ConsistencyLevel::Session(
144-
replace_permission_response.session_token,
145-
)),
146-
)
141+
.delete_permission()
142+
.consistency_level(ConsistencyLevel::Session(
143+
replace_permission_response.session_token,
144+
))
145+
.into_future()
147146
.await
148147
.unwrap();
149148

sdk/data_cosmos/examples/user_permission_token.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
126126
Err(error) => println!("Insert failed: {:#?}", error),
127127
}
128128

129-
permission_client
130-
.delete_permission(Context::new(), DeletePermissionOptions::new())
131-
.await?;
129+
permission_client.delete_permission().into_future().await?;
132130

133131
// All includes read and write.
134132
let permission_mode = get_collection_response.collection.all_permission();

sdk/data_cosmos/src/clients/permission_client.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,8 @@ impl PermissionClient {
8686
}
8787

8888
/// Delete the permission
89-
pub async fn delete_permission(
90-
&self,
91-
ctx: Context,
92-
options: DeletePermissionOptions,
93-
) -> crate::Result<DeletePermissionResponse> {
94-
let mut request = self.prepare_request_with_permission_name(http::Method::DELETE);
95-
96-
options.decorate_request(&mut request)?;
97-
98-
let response = self
99-
.pipeline()
100-
.send(ctx.clone().insert(ResourceType::Permissions), &mut request)
101-
.await?;
102-
103-
Ok(DeletePermissionResponse::try_from(response).await?)
89+
pub fn delete_permission(&self) -> DeletePermissionBuilder {
90+
DeletePermissionBuilder::new(self.clone())
10491
}
10592

10693
pub(crate) fn prepare_request_with_permission_name(&self, method: http::Method) -> Request {

sdk/data_cosmos/src/operations/delete_permission.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,61 @@ use crate::headers::from_headers::*;
22
use crate::prelude::*;
33

44
use azure_core::headers::session_token_from_headers;
5-
use azure_core::Request as HttpRequest;
5+
use azure_core::Context;
66
use azure_core::Response as HttpResponse;
77

88
#[derive(Debug, Clone)]
9-
pub struct DeletePermissionOptions {
9+
pub struct DeletePermissionBuilder {
10+
client: PermissionClient,
1011
consistency_level: Option<ConsistencyLevel>,
12+
context: Context,
1113
}
1214

13-
impl DeletePermissionOptions {
14-
pub fn new() -> Self {
15+
impl DeletePermissionBuilder {
16+
pub(crate) fn new(client: PermissionClient) -> Self {
1517
Self {
18+
client,
1619
consistency_level: None,
20+
context: Context::new(),
1721
}
1822
}
1923

2024
setters! {
2125
consistency_level: ConsistencyLevel => Some(consistency_level),
26+
context: Context => context,
2227
}
2328

24-
pub(crate) fn decorate_request(&self, request: &mut HttpRequest) -> crate::Result<()> {
25-
azure_core::headers::add_optional_header2(&self.consistency_level, request)?;
29+
pub fn into_future(self) -> DeletePermission {
30+
Box::pin(async move {
31+
let mut request = self
32+
.client
33+
.prepare_request_with_permission_name(http::Method::DELETE);
2634

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

0 commit comments

Comments
 (0)