1
+ use crate :: headers:: from_headers:: * ;
1
2
use crate :: prelude:: * ;
2
3
4
+ use azure_core:: headers:: session_token_from_headers;
3
5
use azure_core:: prelude:: * ;
4
- use azure_core:: { Request as HttpRequest , Response as HttpResponse } ;
6
+ use azure_core:: Response as HttpResponse ;
5
7
use chrono:: { DateTime , Utc } ;
6
8
7
9
#[ derive( Debug , Clone ) ]
8
- pub struct DeleteDocumentOptions {
10
+ pub struct DeleteDocumentBuilder {
11
+ client : DocumentClient ,
9
12
if_match_condition : Option < IfMatchCondition > ,
10
13
if_modified_since : Option < IfModifiedSince > ,
11
14
consistency_level : Option < ConsistencyLevel > ,
12
15
allow_tentative_writes : TentativeWritesAllowance ,
16
+ context : Context ,
13
17
}
14
18
15
- impl DeleteDocumentOptions {
16
- pub fn new ( ) -> DeleteDocumentOptions {
19
+ impl DeleteDocumentBuilder {
20
+ pub ( crate ) fn new ( client : DocumentClient ) -> DeleteDocumentBuilder {
17
21
Self {
22
+ client,
18
23
if_match_condition : None ,
19
24
if_modified_since : None ,
20
25
consistency_level : None ,
21
26
allow_tentative_writes : TentativeWritesAllowance :: Deny ,
27
+ context : Context :: new ( ) ,
22
28
}
23
29
}
24
30
@@ -27,29 +33,50 @@ impl DeleteDocumentOptions {
27
33
if_match_condition: IfMatchCondition => Some ( if_match_condition) ,
28
34
allow_tentative_writes: TentativeWritesAllowance ,
29
35
if_modified_since: DateTime <Utc > => Some ( IfModifiedSince :: new( if_modified_since) ) ,
36
+ context: Context => context,
30
37
}
31
38
32
- pub fn decorate_request (
33
- & self ,
34
- request : & mut HttpRequest ,
35
- serialized_partition_key : & str ,
36
- ) -> crate :: Result < ( ) > {
37
- azure_core:: headers:: add_optional_header2 ( & self . if_match_condition , request) ?;
38
- azure_core:: headers:: add_optional_header2 ( & self . if_modified_since , request) ?;
39
- azure_core:: headers:: add_optional_header2 ( & self . consistency_level , request) ?;
40
- azure_core:: headers:: add_mandatory_header2 ( & self . allow_tentative_writes , request) ?;
39
+ pub fn into_future ( self ) -> DeleteDocument {
40
+ Box :: pin ( async move {
41
+ let mut request = self
42
+ . client
43
+ . prepare_request_pipeline_with_document_name ( http:: Method :: DELETE ) ;
44
+
45
+ azure_core:: headers:: add_optional_header2 ( & self . if_match_condition , & mut request) ?;
46
+ azure_core:: headers:: add_optional_header2 ( & self . if_modified_since , & mut request) ?;
47
+ azure_core:: headers:: add_optional_header2 ( & self . consistency_level , & mut request) ?;
48
+ azure_core:: headers:: add_mandatory_header2 ( & self . allow_tentative_writes , & mut request) ?;
41
49
42
- crate :: cosmos_entity:: add_as_partition_key_header_serialized2 (
43
- serialized_partition_key ,
44
- request,
45
- ) ;
50
+ crate :: cosmos_entity:: add_as_partition_key_header_serialized2 (
51
+ & self . client . partition_key_serialized ( ) ,
52
+ & mut request,
53
+ ) ;
46
54
47
- Ok ( ( ) )
55
+ let response = self
56
+ . client
57
+ . cosmos_client ( )
58
+ . pipeline ( )
59
+ . send (
60
+ self . context . clone ( ) . insert ( ResourceType :: Documents ) ,
61
+ & mut request,
62
+ )
63
+ . await ?;
64
+
65
+ DeleteDocumentResponse :: try_from ( response) . await
66
+ } )
48
67
}
49
68
}
50
69
51
- use crate :: headers:: from_headers:: * ;
52
- use azure_core:: headers:: session_token_from_headers;
70
+ type DeleteDocument = futures:: future:: BoxFuture < ' static , crate :: Result < DeleteDocumentResponse > > ;
71
+
72
+ #[ cfg( feature = "into_future" ) ]
73
+ impl std:: future:: IntoFuture for DeleteDocumentBuilder {
74
+ type Future = DeleteDocument ;
75
+ type Output = <DeleteDocument as std:: future:: Future >:: Output ;
76
+ fn into_future ( self ) -> Self :: Future {
77
+ Self :: into_future ( self )
78
+ }
79
+ }
53
80
54
81
#[ derive( Debug , Clone ) ]
55
82
pub struct DeleteDocumentResponse {
0 commit comments