@@ -4,26 +4,28 @@ use crate::resources::Document;
4
4
use crate :: ResourceQuota ;
5
5
use azure_core:: headers:: { etag_from_headers, session_token_from_headers} ;
6
6
use azure_core:: prelude:: * ;
7
- use azure_core:: {
8
- collect_pinned_stream, Request as HttpRequest , Response as HttpResponse , SessionToken ,
9
- } ;
7
+ use azure_core:: { collect_pinned_stream, Response as HttpResponse , SessionToken } ;
10
8
use chrono:: { DateTime , Utc } ;
11
9
use http:: { HeaderMap , StatusCode } ;
12
10
use serde:: de:: DeserializeOwned ;
13
11
14
12
#[ derive( Debug , Clone ) ]
15
- pub struct GetDocumentOptions {
13
+ pub struct GetDocumentBuilder {
14
+ client : DocumentClient ,
16
15
if_match_condition : Option < IfMatchCondition > ,
17
16
if_modified_since : Option < IfModifiedSince > ,
18
17
consistency_level : Option < ConsistencyLevel > ,
18
+ context : Context ,
19
19
}
20
20
21
- impl GetDocumentOptions {
22
- pub fn new ( ) -> Self {
21
+ impl GetDocumentBuilder {
22
+ pub ( crate ) fn new ( client : DocumentClient ) -> Self {
23
23
Self {
24
+ client,
24
25
if_match_condition : None ,
25
26
if_modified_since : None ,
26
27
consistency_level : None ,
28
+ context : Context :: new ( ) ,
27
29
}
28
30
}
29
31
@@ -33,14 +35,41 @@ impl GetDocumentOptions {
33
35
if_modified_since: DateTime <Utc > => Some ( IfModifiedSince :: new( if_modified_since) ) ,
34
36
}
35
37
36
- pub ( crate ) fn decorate_request ( & self , request : & mut HttpRequest ) -> 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) ?;
38
+ pub fn into_future < T : DeserializeOwned > ( self ) -> GetDocument < T > {
39
+ Box :: pin ( async move {
40
+ let mut request = self
41
+ . client
42
+ . prepare_request_pipeline_with_document_name ( http:: Method :: GET ) ;
43
+
44
+ azure_core:: headers:: add_optional_header2 ( & self . if_match_condition , & mut request) ?;
45
+ azure_core:: headers:: add_optional_header2 ( & self . if_modified_since , & mut request) ?;
46
+ azure_core:: headers:: add_optional_header2 ( & self . consistency_level , & mut request) ?;
47
+
48
+ request. set_body ( azure_core:: EMPTY_BODY . into ( ) ) ;
49
+
50
+ let response = self
51
+ . client
52
+ . cosmos_client ( )
53
+ . pipeline ( )
54
+ . send (
55
+ self . context . clone ( ) . insert ( ResourceType :: Documents ) ,
56
+ & mut request,
57
+ )
58
+ . await ?;
59
+
60
+ GetDocumentResponse :: try_from ( response) . await
61
+ } )
62
+ }
63
+ }
40
64
41
- request . set_body ( azure_core :: EMPTY_BODY . into ( ) ) ;
65
+ type GetDocument < T > = futures :: future :: BoxFuture < ' static , crate :: Result < GetDocumentResponse < T > > > ;
42
66
43
- Ok ( ( ) )
67
+ #[ cfg( feature = "into_future" ) ]
68
+ impl std:: future:: IntoFuture for GetDocumentBuilder {
69
+ type Future = GetDocument ;
70
+ type Output = <GetDocument as std:: future:: Future >:: Output ;
71
+ fn into_future ( self ) -> Self :: Future {
72
+ Self :: into_future ( self )
44
73
}
45
74
}
46
75
0 commit comments