1
1
#[ macro_use]
2
2
extern crate log;
3
3
4
+ use azure_sdk_core:: errors:: AzureError ;
4
5
use azure_sdk_core:: prelude:: * ;
5
6
use azure_sdk_storage_blob:: prelude:: * ;
6
7
use azure_sdk_storage_core:: prelude:: * ;
7
8
use std:: error:: Error ;
9
+ use std:: sync:: Arc ;
8
10
9
11
#[ tokio:: main]
10
12
async fn main ( ) -> Result < ( ) , Box < dyn Error > > {
@@ -22,7 +24,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
22
24
. expect ( "please specify blob name as command line parameter" ) ;
23
25
24
26
let client: Box < dyn Client > = Box :: new ( client:: with_access_key ( & account, & master_key) ) ;
27
+ let s_content = get_blob_box ( & client, & container, & blob) . await ?;
28
+ println ! ( "blob == {:?}" , blob) ;
29
+ println ! ( "s_content == {}" , s_content) ;
30
+
31
+ let client: Arc < dyn Client > = Arc :: new ( client:: with_access_key ( & account, & master_key) ) ;
32
+ let s_content = get_blob_arc ( client, & container, & blob) . await ?;
33
+ println ! ( "blob == {:?}" , blob) ;
34
+ println ! ( "s_content == {}" , s_content) ;
25
35
36
+ Ok ( ( ) )
37
+ }
38
+
39
+ async fn get_blob_box < ' a > (
40
+ client : & ' a Box < dyn Client > ,
41
+ container : & ' a str ,
42
+ blob : & ' a str ,
43
+ ) -> Result < String , AzureError > {
26
44
trace ! ( "Requesting blob" ) ;
27
45
28
46
let response = client
@@ -32,9 +50,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
32
50
. finalize ( )
33
51
. await ?;
34
52
35
- let s_content = String :: from_utf8 ( response. data ) ?;
36
- println ! ( "blob == {:?}" , blob) ;
37
- println ! ( "s_content == {}" , s_content) ;
53
+ Ok ( String :: from_utf8 ( response. data ) ?)
54
+ }
38
55
39
- Ok ( ( ) )
56
+ async fn get_blob_arc < ' a > (
57
+ client : Arc < dyn Client > ,
58
+ container : & ' a str ,
59
+ blob : & ' a str ,
60
+ ) -> Result < String , AzureError > {
61
+ trace ! ( "Requesting blob" ) ;
62
+
63
+ let response = client
64
+ . get_blob ( )
65
+ . with_container_name ( & container)
66
+ . with_blob_name ( & blob)
67
+ . finalize ( )
68
+ . await ?;
69
+
70
+ Ok ( String :: from_utf8 ( response. data ) ?)
40
71
}
0 commit comments