Skip to content
This repository was archived by the owner on Oct 6, 2020. It is now read-only.

Commit d13d5f6

Browse files
author
Francesco Cogno
authored
Azure Storage Core: Added ?Sized on impl (#308)
* Added ?Sized on impl * bumped deps
1 parent 1036adc commit d13d5f6

File tree

18 files changed

+81
-67
lines changed

18 files changed

+81
-67
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[![Build Status](https://travis-ci.org/MindFlavor/AzureSDKForRust.svg?branch=master)](https://travis-ci.org/MindFlavor/AzureSDKForRust) [![Coverage Status](https://coveralls.io/repos/MindFlavor/AzureSDKForRust/badge.svg?branch=master&service=github)](https://coveralls.io/github/MindFlavor/AzureSDKForRust?branch=master) ![stability-unstable](https://img.shields.io/badge/stability-unstable-yellow.svg)
77

8-
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/storage_blob_0.44.3) [![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/storage_blob_0.44.3) [![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/storage_blob_0.44.3)](https://github.com/MindFlavor/AzureSDKForRust/commits/master)
8+
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/storage_core_0.44.3) [![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/storage_core_0.44.3) [![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/storage_core_0.44.3)](https://github.com/MindFlavor/AzureSDKForRust/commits/master)
99

1010
[![GitHub contributors](https://img.shields.io/github/contributors/MindFlavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/graphs/contributors)
1111

azure_sdk_storage_account/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_storage_account"
3-
version = "0.41.2"
3+
version = "0.41.3"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Blob storage account crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <[email protected]>", "Max Gortman <[email protected]>"]
@@ -16,7 +16,7 @@ edition = "2018"
1616

1717
[dependencies]
1818
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" }
19-
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.2" }
19+
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" }
2020
chrono = "0.4"
2121
http = "0.2"
2222
hyper = "0.13"

azure_sdk_storage_blob/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_storage_blob"
3-
version = "0.44.3"
3+
version = "0.44.4"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Blob storage crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <[email protected]>", "Max Gortman <[email protected]>", "Dong Liu <[email protected]>"]
@@ -16,7 +16,7 @@ edition = "2018"
1616

1717
[dependencies]
1818
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" }
19-
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.2" }
19+
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" }
2020
md5 = "0.7"
2121
RustyXML = "0.3"
2222
base64 = "0.12"

azure_sdk_storage_blob/examples/blob_03_boxed_client.rs

+35-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#[macro_use]
22
extern crate log;
33

4+
use azure_sdk_core::errors::AzureError;
45
use azure_sdk_core::prelude::*;
56
use azure_sdk_storage_blob::prelude::*;
67
use azure_sdk_storage_core::prelude::*;
78
use std::error::Error;
9+
use std::sync::Arc;
810

911
#[tokio::main]
1012
async fn main() -> Result<(), Box<dyn Error>> {
@@ -22,7 +24,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
2224
.expect("please specify blob name as command line parameter");
2325

2426
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);
2535

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> {
2644
trace!("Requesting blob");
2745

2846
let response = client
@@ -32,9 +50,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
3250
.finalize()
3351
.await?;
3452

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+
}
3855

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)?)
4071
}

azure_sdk_storage_blob/src/blob/block_list.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::blob::{BlobBlockType, BlockWithSizeList};
2-
use base64;
32
use std::borrow::Borrow;
43

54
#[derive(Default, Debug, Clone, PartialEq)]

azure_sdk_storage_blob/src/blob/block_with_size_list.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::blob::BlobBlockType;
22
use crate::blob::BlobBlockWithSize;
33
use azure_sdk_core::errors::AzureError;
4-
use base64;
54
use std::borrow::Borrow;
65

76
#[derive(Debug, Deserialize)]

azure_sdk_storage_blob/src/blob/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ pub(crate) fn incomplete_vector_from_response(
423423
}
424424

425425
#[inline]
426-
pub(crate) fn generate_blob_uri<'a, C>(
426+
pub(crate) fn generate_blob_uri<C>(
427427
t: &C,
428428
container_name: &str,
429429
blob_name: &str,

azure_sdk_storage_blob/src/blob/requests/put_block_list_builder.json

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"azure_sdk_core::lease::LeaseId",
1111
"azure_sdk_core::prelude::*",
1212
"hyper::{Method, StatusCode}",
13-
"md5",
1413
"azure_sdk_storage_core::prelude::*",
1514
"azure_sdk_core::add_content_md5_header",
1615
"azure_sdk_core::{Yes, No, ToAssign}",

azure_sdk_storage_blob/src/blob/requests/put_block_list_builder.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use azure_sdk_core::prelude::*;
99
use azure_sdk_core::{No, ToAssign, Yes};
1010
use azure_sdk_storage_core::prelude::*;
1111
use hyper::{Method, StatusCode};
12-
use md5;
1312
use std::borrow::Borrow;
1413
use std::collections::HashMap;
1514
use std::marker::PhantomData;

azure_sdk_storage_blob/src/container/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,7 @@ pub(crate) fn incomplete_vector_from_container_response(
277277
}
278278

279279
#[inline]
280-
pub(crate) fn generate_container_uri<'a, C>(
281-
c: &C,
282-
container_name: &str,
283-
params: Option<&str>,
284-
) -> String
280+
pub(crate) fn generate_container_uri<C>(c: &C, container_name: &str, params: Option<&str>) -> String
285281
where
286282
C: Client,
287283
{

azure_sdk_storage_core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_storage_core"
3-
version = "0.44.2"
3+
version = "0.44.3"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Core storage crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <[email protected]>", "Max Gortman <[email protected]>", "Dong Liu <[email protected]>"]

azure_sdk_storage_core/examples/box.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
use azure_sdk_storage_core::prelude::*;
2+
use std::sync::Arc;
23
use std::thread;
34

45
fn get_box() -> Box<dyn Client> {
56
Box::new(client::with_access_key("fake", "fake"))
67
}
78

8-
fn get_box_send() -> Box<dyn Client + Send + Sync> {
9-
Box::new(client::with_access_key("fake", "fake"))
9+
fn get_box_send() -> Box<dyn Client> {
10+
Box::new(client::with_access_key("send", "fake"))
11+
}
12+
13+
fn get_arc() -> Arc<dyn Client> {
14+
Arc::new(client::with_access_key("arc", "fake"))
1015
}
1116

1217
pub fn main() {
@@ -19,4 +24,7 @@ pub fn main() {
1924
println!("client_send.blob_uri() == {}", client_send.blob_uri());
2025
});
2126
handler.join().unwrap();
27+
28+
let client_arc = get_arc();
29+
println!("client_arc.blob_uri() == {}", client_arc.blob_uri());
2230
}

azure_sdk_storage_core/src/client.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub trait Client: Send + Sync {
4545

4646
impl<C> Client for Box<C>
4747
where
48-
C: Client,
48+
C: Client + ?Sized,
4949
{
5050
fn blob_uri(&self) -> &str {
5151
self.as_ref().blob_uri()
@@ -77,7 +77,10 @@ where
7777
}
7878
}
7979

80-
impl Client for Box<dyn Client> {
80+
impl<C> Client for std::sync::Arc<C>
81+
where
82+
C: Client + ?Sized,
83+
{
8184
fn blob_uri(&self) -> &str {
8285
self.as_ref().blob_uri()
8386
}
@@ -191,7 +194,7 @@ pub fn from_connection_string(connection_string: &str) -> Result<KeyClient, Azur
191194
format!("https://{}.table.core.windows.net", account),
192195
)),
193196
_ => {
194-
return Err(AzureError::GenericErrorWithText(
197+
Err(AzureError::GenericErrorWithText(
195198
"Could not create a storage client from the provided connection string. Please validate that you have specified the account name and means of authentication (key, SAS, etc.)."
196199
.to_owned(),
197200
))

azure_sdk_storage_core/src/connection_string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ impl<'a> ConnectionString<'a> {
153153
let mut file_secondary_endpoint = None;
154154

155155
let kv_str_pairs = connection_string
156-
.split(";")
156+
.split(';')
157157
.filter(|s| !s.chars().all(char::is_whitespace));
158158

159159
for kv_pair_str in kv_str_pairs {
160-
let mut kv = kv_pair_str.trim().split("=");
160+
let mut kv = kv_pair_str.trim().split('=');
161161
let k = match kv.next() {
162162
Some(k) if k.chars().all(char::is_whitespace) => {
163163
return Err(ConnectionStringError::ParsingError {

azure_sdk_storage_core/src/connection_string_builder.rs

+16-35
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ use crate::connection_string::*;
22

33
pub struct ConnectionStringBuilder<'a>(ConnectionString<'a>);
44

5+
impl<'a> Default for ConnectionStringBuilder<'a> {
6+
fn default() -> Self {
7+
Self(ConnectionString::default())
8+
}
9+
}
10+
511
impl<'a> ConnectionStringBuilder<'a> {
612
pub fn new() -> Self {
713
Self(ConnectionString::default())
@@ -32,73 +38,48 @@ impl<'a> ConnectionStringBuilder<'a> {
3238
));
3339
}
3440
if let Some(endpoint_suffix) = self.0.endpoint_suffix {
35-
kv_pairs.push(format!(
36-
"{}={}",
37-
ENDPOINT_SUFFIX_KEY_NAME,
38-
endpoint_suffix
39-
));
41+
kv_pairs.push(format!("{}={}", ENDPOINT_SUFFIX_KEY_NAME, endpoint_suffix));
4042
}
4143
if let Some(default_endpoints_protocol) = self.0.default_endpoints_protocol.as_ref() {
4244
kv_pairs.push(format!(
4345
"{}={}",
44-
DEFAULT_ENDPOINTS_PROTOCOL_KEY_NAME,
45-
default_endpoints_protocol
46+
DEFAULT_ENDPOINTS_PROTOCOL_KEY_NAME, default_endpoints_protocol
4647
));
4748
}
4849
if let Some(blob_endpoint) = self.0.blob_endpoint {
49-
kv_pairs.push(format!(
50-
"{}={}",
51-
BLOB_ENDPOINT_KEY_NAME,
52-
blob_endpoint
53-
));
50+
kv_pairs.push(format!("{}={}", BLOB_ENDPOINT_KEY_NAME, blob_endpoint));
5451
}
5552
if let Some(blob_secondary_endpoint) = self.0.blob_secondary_endpoint {
5653
kv_pairs.push(format!(
5754
"{}={}",
58-
BLOB_SECONDARY_ENDPOINT_KEY_NAME,
59-
blob_secondary_endpoint
55+
BLOB_SECONDARY_ENDPOINT_KEY_NAME, blob_secondary_endpoint
6056
));
6157
}
6258
if let Some(table_endpoint) = self.0.table_endpoint {
63-
kv_pairs.push(format!(
64-
"{}={}",
65-
TABLE_ENDPOINT_KEY_NAME,
66-
table_endpoint
67-
));
59+
kv_pairs.push(format!("{}={}", TABLE_ENDPOINT_KEY_NAME, table_endpoint));
6860
}
6961
if let Some(table_secondary_endpoint) = self.0.table_secondary_endpoint {
7062
kv_pairs.push(format!(
7163
"{}={}",
72-
TABLE_SECONDARY_ENDPOINT_KEY_NAME,
73-
table_secondary_endpoint
64+
TABLE_SECONDARY_ENDPOINT_KEY_NAME, table_secondary_endpoint
7465
));
7566
}
7667
if let Some(queue_endpoint) = self.0.queue_endpoint {
77-
kv_pairs.push(format!(
78-
"{}={}",
79-
QUEUE_ENDPOINT_KEY_NAME,
80-
queue_endpoint
81-
));
68+
kv_pairs.push(format!("{}={}", QUEUE_ENDPOINT_KEY_NAME, queue_endpoint));
8269
}
8370
if let Some(queue_secondary_endpoint) = self.0.queue_secondary_endpoint {
8471
kv_pairs.push(format!(
8572
"{}={}",
86-
QUEUE_SECONDARY_ENDPOINT_KEY_NAME,
87-
queue_secondary_endpoint
73+
QUEUE_SECONDARY_ENDPOINT_KEY_NAME, queue_secondary_endpoint
8874
));
8975
}
9076
if let Some(file_endpoint) = self.0.file_endpoint {
91-
kv_pairs.push(format!(
92-
"{}={}",
93-
FILE_ENDPOINT_KEY_NAME,
94-
file_endpoint
95-
));
77+
kv_pairs.push(format!("{}={}", FILE_ENDPOINT_KEY_NAME, file_endpoint));
9678
}
9779
if let Some(file_secondary_endpoint) = self.0.file_secondary_endpoint {
9880
kv_pairs.push(format!(
9981
"{}={}",
100-
FILE_SECONDARY_ENDPOINT_KEY_NAME,
101-
file_secondary_endpoint
82+
FILE_SECONDARY_ENDPOINT_KEY_NAME, file_secondary_endpoint
10283
));
10384
}
10485

azure_sdk_storage_core/src/rest_client.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ use crate::{ClientEndpoint, HyperClientEndpoint};
33
use azure_sdk_core::errors::AzureError;
44
use azure_sdk_core::headers;
55
use azure_sdk_core::util::{format_header_value, HeaderMapExt, RequestBuilderExt};
6-
use base64;
7-
use chrono;
86
use chrono::{DateTime, Utc};
97
use http::request::Builder;
108
use hyper::{self, header, HeaderMap, Method};
119
use ring::hmac;
1210
use std::fmt::Write;
13-
use url;
1411
use url::form_urlencoded;
1512

1613
#[derive(Debug, Clone, Copy)]
@@ -74,6 +71,7 @@ pub(crate) enum SASType {
7471
Table,
7572
}
7673

74+
#[allow(clippy::too_many_arguments)]
7775
pub(crate) fn generate_storage_sas<CE: ClientEndpoint>(
7876
client_endpoint: &CE,
7977
start: Option<&DateTime<Utc>>,

azure_sdk_storage_core/src/shared_access_signature.rs

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub struct SharedAccessSignature {
143143
}
144144

145145
impl SharedAccessSignature {
146+
#[allow(clippy::new_ret_no_self)]
146147
pub fn new(key_client: &KeyClient) -> SharedAccessSignatureBuilder<No, No, No, No> {
147148
SharedAccessSignatureBuilder::new(key_client)
148149
}

azure_sdk_storage_table/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_storage_table"
3-
version = "0.41.2"
3+
version = "0.41.3"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Table storage crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <[email protected]>", "gzp-crey", "Max Gortman <[email protected]>", "Dong Liu <[email protected]>"]
@@ -16,7 +16,7 @@ edition = "2018"
1616

1717
[dependencies]
1818
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" }
19-
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.2" }
19+
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" }
2020
chrono = "0.4"
2121
http = "0.2"
2222
hyper = "0.13"

0 commit comments

Comments
 (0)