From c99bbc0b9efad5b2e0468caa82ccbe85cf257b7f Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Sat, 16 Jan 2021 11:44:48 -0800 Subject: [PATCH] Bytes for storage --- sdk/storage/examples/blob_range.rs | 4 ++-- sdk/storage/examples/connection_string.rs | 4 ++-- sdk/storage/examples/container_and_blob.rs | 7 +++--- sdk/storage/examples/list_blobs_00.rs | 4 ++-- sdk/storage/examples/put_block_blob_00.rs | 7 +++--- sdk/storage/examples/put_page_blob_00.rs | 11 +++++---- sdk/storage/examples/stream_blob_00.rs | 2 +- .../blob/requests/append_block_builder.rs | 9 ++++---- .../blob/requests/put_block_blob_builder.rs | 9 ++++---- .../blob/blob/requests/put_block_builder.rs | 13 +++++++---- .../blob/requests/put_block_list_builder.rs | 5 ++-- .../blob/blob/requests/update_page_builder.rs | 9 ++++---- .../container/requests/set_acl_builder.rs | 3 ++- sdk/storage/src/clients/blob_client.rs | 23 +++++++++++-------- sdk/storage/src/clients/blob_lease_client.rs | 5 ++-- sdk/storage/src/clients/container_client.rs | 5 ++-- .../src/clients/container_lease_client.rs | 5 ++-- .../src/clients/storage_account_client.rs | 7 +++--- sdk/storage/src/clients/storage_client.rs | 5 ++-- sdk/storage/src/clients/table_client.rs | 5 ++-- .../src/clients/table_service_client.rs | 5 ++-- .../table/requests/insert_entity_builder.rs | 3 ++- sdk/storage/tests/stream_list_blobs.rs | 2 +- 23 files changed, 89 insertions(+), 63 deletions(-) diff --git a/sdk/storage/examples/blob_range.rs b/sdk/storage/examples/blob_range.rs index 0669e390c3..20a8323c72 100644 --- a/sdk/storage/examples/blob_range.rs +++ b/sdk/storage/examples/blob_range.rs @@ -43,7 +43,7 @@ async fn main() -> Result<(), Box> { let content = std::str::from_utf8(&buf)?.to_owned(); println!("content == {}", content); - let _response = blob.put_block_blob(&buf).execute().await?; + let _response = blob.put_block_blob(buf.clone()).execute().await?; let whole = blob.get().execute().await?; @@ -70,7 +70,7 @@ async fn main() -> Result<(), Box> { let mut stream = Box::pin(blob.get().stream(512)); println!("\nStreaming"); - let mut chunk = 0; + let mut chunk: usize = 0; while let Some(value) = stream.next().await { let value = value?; println!("received {:?} bytes", value.len()); diff --git a/sdk/storage/examples/connection_string.rs b/sdk/storage/examples/connection_string.rs index 0539f01abc..96b6a22146 100644 --- a/sdk/storage/examples/connection_string.rs +++ b/sdk/storage/examples/connection_string.rs @@ -47,7 +47,7 @@ async fn main() -> Result<(), Box> { for i in 0..10u8 { container .as_blob_client(format!("blob{}.txt", i)) - .put_block_blob("somedata".as_bytes()) + .put_block_blob("somedata") .content_type("text/plain") .execute() .await?; @@ -68,7 +68,7 @@ async fn main() -> Result<(), Box> { let mut stream = Box::pin(container.list_blobs().max_results(max_results).stream()); - let mut cnt = 0; + let mut cnt: i32 = 0; while let Some(value) = stream.next().await { let len = value?.incomplete_vector.len(); println!("received {} blobs", len); diff --git a/sdk/storage/examples/container_and_blob.rs b/sdk/storage/examples/container_and_blob.rs index 2692cb5b4c..c450b1e8f0 100644 --- a/sdk/storage/examples/container_and_blob.rs +++ b/sdk/storage/examples/container_and_blob.rs @@ -1,6 +1,7 @@ use azure_core::prelude::*; use azure_storage::blob::prelude::*; use azure_storage::core::prelude::*; +use bytes::Bytes; use std::error::Error; use std::sync::Arc; @@ -31,7 +32,7 @@ async fn main() -> Result<(), Box> { .await?; println!("{:?}", res); - let data = b"something"; + let data = Bytes::from_static(b"something"); // this is not mandatory but it helps preventing // spurious data to be uploaded. @@ -39,7 +40,7 @@ async fn main() -> Result<(), Box> { let res = container .as_blob_client("blob0.txt") - .put_block_blob(data) + .put_block_blob(data.clone()) .content_type("text/plain") .hash(&hash) .execute() @@ -48,7 +49,7 @@ async fn main() -> Result<(), Box> { let res = container .as_blob_client("blob1.txt") - .put_block_blob(data) + .put_block_blob(data.clone()) .content_type("text/plain") .hash(&hash) .execute() diff --git a/sdk/storage/examples/list_blobs_00.rs b/sdk/storage/examples/list_blobs_00.rs index 0e4b1aad1c..202b16b57a 100644 --- a/sdk/storage/examples/list_blobs_00.rs +++ b/sdk/storage/examples/list_blobs_00.rs @@ -49,7 +49,7 @@ async fn main() -> Result<(), Box> { for i in 0..10u8 { container .as_blob_client(format!("blob{}.txt", i)) - .put_block_blob("somedata".as_bytes()) + .put_block_blob("somedata") .content_type("text/plain") .execute() .await?; @@ -74,7 +74,7 @@ async fn main() -> Result<(), Box> { .stream(), ); - let mut cnt = 0; + let mut cnt: i32 = 0; while let Some(value) = stream.next().await { let len = value?.incomplete_vector.len(); println!("received {} blobs", len); diff --git a/sdk/storage/examples/put_block_blob_00.rs b/sdk/storage/examples/put_block_blob_00.rs index c59ecf6211..67bc40ff02 100644 --- a/sdk/storage/examples/put_block_blob_00.rs +++ b/sdk/storage/examples/put_block_blob_00.rs @@ -4,6 +4,7 @@ extern crate log; use azure_core::prelude::*; use azure_storage::blob::prelude::*; use azure_storage::core::prelude::*; +use bytes::Bytes; use std::error::Error; use std::sync::Arc; use std::time::Duration; @@ -34,7 +35,7 @@ async fn main() -> Result<(), Box> { .as_container_client(&container) .as_blob_client(&blob_name); - let data = b"something"; + let data = Bytes::from_static(b"something"); // this is not mandatory but it helps preventing // spurious data to be uploaded. @@ -45,7 +46,7 @@ async fn main() -> Result<(), Box> { // parameters (such as LeaseID, or ContentDisposition, MD5 etc...) // so make sure to check with the documentation. let res = blob - .put_block_blob(data) + .put_block_blob(data.clone()) .content_type("text/plain") .hash(&hash) .execute() @@ -61,7 +62,7 @@ async fn main() -> Result<(), Box> { .push(BlobBlockType::Uncommitted(b"pollastro" as &[u8])); let res = blob - .put_block(&("satanasso".into()), data) + .put_block(&("satanasso".into()), data.clone()) .execute() .await?; println!("2-put_block {:?}", res); diff --git a/sdk/storage/examples/put_page_blob_00.rs b/sdk/storage/examples/put_page_blob_00.rs index 72038c4549..c1dac4199b 100644 --- a/sdk/storage/examples/put_page_blob_00.rs +++ b/sdk/storage/examples/put_page_blob_00.rs @@ -2,6 +2,7 @@ extern crate log; use azure_core::prelude::*; use azure_storage::clients::*; +use bytes::Bytes; use std::error::Error; use std::sync::Arc; @@ -31,17 +32,17 @@ async fn main() -> Result<(), Box> { .as_container_client(&container_name); let blob = container.as_blob_client(&blob_name); - let data: [u8; 2000] = [51; 2000]; + let data = Bytes::from_static(&[51; 2000]); let mut metadata = Metadata::new(); metadata.insert("pollo", "arrosto"); metadata.insert("milk", "shake"); - let slice = &data[512..1024]; + let slice = data.slice(512..1024); // this is not mandatory but it helps preventing // spurious data to be uploaded. - let digest = md5::compute(slice); + let digest = md5::compute(slice.clone()); // The required parameters are container_name_name, blob_name. // The builder supports many more optional @@ -60,7 +61,7 @@ async fn main() -> Result<(), Box> { // the size of tha page or a buffer out // of bounds error will be thrown. let res = blob - .update_page(BA512Range::new(0, 511)?, slice) + .update_page(BA512Range::new(0, 511)?, slice.clone()) .hash(&digest.into()) .execute() .await?; @@ -68,7 +69,7 @@ async fn main() -> Result<(), Box> { // update a second page with the same data let res = blob - .update_page(BA512Range::new(512, 1023)?, slice) + .update_page(BA512Range::new(512, 1023)?, slice.clone()) .hash(&digest.into()) .execute() .await?; diff --git a/sdk/storage/examples/stream_blob_00.rs b/sdk/storage/examples/stream_blob_00.rs index b34e6af2be..d72ad56f73 100644 --- a/sdk/storage/examples/stream_blob_00.rs +++ b/sdk/storage/examples/stream_blob_00.rs @@ -36,7 +36,7 @@ async fn main() -> Result<(), Box> { let string = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"; let _response = blob - .put_block_blob(string.as_bytes()) + .put_block_blob(string) .content_type("text/plain") .execute() .await?; diff --git a/sdk/storage/src/blob/blob/requests/append_block_builder.rs b/sdk/storage/src/blob/blob/requests/append_block_builder.rs index 9abf275130..6b1788a2cd 100644 --- a/sdk/storage/src/blob/blob/requests/append_block_builder.rs +++ b/sdk/storage/src/blob/blob/requests/append_block_builder.rs @@ -3,11 +3,12 @@ use crate::blob::prelude::*; use crate::core::prelude::*; use azure_core::headers::{add_optional_header, add_optional_header_ref}; use azure_core::prelude::*; +use bytes::Bytes; #[derive(Debug, Clone)] pub struct AppendBlockBuilder<'a> { blob_client: &'a BlobClient, - body: &'a [u8], + body: Bytes, hash: Option<&'a Hash>, condition_max_size: Option, condition_append_position: Option, @@ -17,10 +18,10 @@ pub struct AppendBlockBuilder<'a> { } impl<'a> AppendBlockBuilder<'a> { - pub(crate) fn new(blob_client: &'a BlobClient, body: &'a [u8]) -> Self { + pub(crate) fn new(blob_client: &'a BlobClient, body: impl Into) -> Self { Self { blob_client, - body, + body: body.into(), hash: None, condition_max_size: None, condition_append_position: None, @@ -68,7 +69,7 @@ impl<'a> AppendBlockBuilder<'a> { request = add_optional_header(&self.client_request_id, request); request }, - Some(self.body), + Some(self.body.clone()), )?; let response = self diff --git a/sdk/storage/src/blob/blob/requests/put_block_blob_builder.rs b/sdk/storage/src/blob/blob/requests/put_block_blob_builder.rs index 6f6e5f3975..254a66b4f0 100644 --- a/sdk/storage/src/blob/blob/requests/put_block_blob_builder.rs +++ b/sdk/storage/src/blob/blob/requests/put_block_blob_builder.rs @@ -4,11 +4,12 @@ use crate::core::prelude::*; use azure_core::headers::BLOB_TYPE; use azure_core::headers::{add_mandatory_header, add_optional_header, add_optional_header_ref}; use azure_core::prelude::*; +use bytes::Bytes; #[derive(Debug, Clone)] pub struct PutBlockBlobBuilder<'a> { blob_client: &'a BlobClient, - body: &'a [u8], + body: Bytes, hash: Option<&'a Hash>, content_type: Option>, content_encoding: Option>, @@ -23,10 +24,10 @@ pub struct PutBlockBlobBuilder<'a> { } impl<'a> PutBlockBlobBuilder<'a> { - pub(crate) fn new(blob_client: &'a BlobClient, body: &'a [u8]) -> Self { + pub(crate) fn new(blob_client: &'a BlobClient, body: impl Into) -> Self { Self { blob_client, - body, + body: body.into(), hash: None, content_type: None, content_encoding: None, @@ -86,7 +87,7 @@ impl<'a> PutBlockBlobBuilder<'a> { request = add_optional_header(&self.client_request_id, request); request }, - Some(self.body), + Some(self.body.clone()), )?; let response = self diff --git a/sdk/storage/src/blob/blob/requests/put_block_builder.rs b/sdk/storage/src/blob/blob/requests/put_block_builder.rs index 884cdc04ff..27978cae3f 100644 --- a/sdk/storage/src/blob/blob/requests/put_block_builder.rs +++ b/sdk/storage/src/blob/blob/requests/put_block_builder.rs @@ -3,12 +3,13 @@ use crate::blob::prelude::*; use crate::core::prelude::*; use azure_core::headers::{add_optional_header, add_optional_header_ref}; use azure_core::prelude::*; +use bytes::Bytes; #[derive(Debug, Clone)] pub struct PutBlockBuilder<'a> { blob_client: &'a BlobClient, block_id: &'a BlockId, - body: &'a [u8], + body: Bytes, hash: Option<&'a Hash>, client_request_id: Option>, timeout: Option, @@ -16,11 +17,15 @@ pub struct PutBlockBuilder<'a> { } impl<'a> PutBlockBuilder<'a> { - pub(crate) fn new(blob_client: &'a BlobClient, block_id: &'a BlockId, body: &'a [u8]) -> Self { + pub(crate) fn new( + blob_client: &'a BlobClient, + block_id: &'a BlockId, + body: impl Into, + ) -> Self { Self { blob_client, block_id, - body, + body: body.into(), hash: None, client_request_id: None, timeout: None, @@ -60,7 +65,7 @@ impl<'a> PutBlockBuilder<'a> { request = add_optional_header_ref(&self.lease_id, request); request }, - Some(self.body), + Some(self.body.clone()), )?; trace!("request.headers() == {:#?}", request.headers()); diff --git a/sdk/storage/src/blob/blob/requests/put_block_list_builder.rs b/sdk/storage/src/blob/blob/requests/put_block_list_builder.rs index cf6fe45da2..47055d5c6f 100644 --- a/sdk/storage/src/blob/blob/requests/put_block_list_builder.rs +++ b/sdk/storage/src/blob/blob/requests/put_block_list_builder.rs @@ -3,6 +3,7 @@ use crate::blob::prelude::*; use crate::core::prelude::*; use azure_core::headers::{add_mandatory_header, add_optional_header, add_optional_header_ref}; use azure_core::prelude::*; +use bytes::Bytes; use std::borrow::Borrow; #[derive(Debug, Clone)] @@ -65,12 +66,12 @@ where trace!("url == {:?}", url); let body = self.block_list.to_xml(); - let body_bytes = body.as_bytes(); + let body_bytes = Bytes::from(body); // calculate the xml MD5. This can be made optional // if needed, but i think it's best to calculate it. let md5 = { - let hash = md5::compute(body_bytes); + let hash = md5::compute(body_bytes.clone()); debug!("md5 hash: {:02X}", hash); base64::encode(hash.0) }; diff --git a/sdk/storage/src/blob/blob/requests/update_page_builder.rs b/sdk/storage/src/blob/blob/requests/update_page_builder.rs index 6d95aa66bc..409bf99534 100644 --- a/sdk/storage/src/blob/blob/requests/update_page_builder.rs +++ b/sdk/storage/src/blob/blob/requests/update_page_builder.rs @@ -4,12 +4,13 @@ use crate::core::prelude::*; use azure_core::headers::{add_mandatory_header, add_optional_header, add_optional_header_ref}; use azure_core::headers::{BLOB_TYPE, PAGE_WRITE}; use azure_core::prelude::*; +use bytes::Bytes; #[derive(Debug, Clone)] pub struct UpdatePageBuilder<'a> { blob_client: &'a BlobClient, ba512_range: BA512Range, - content: &'a [u8], + content: Bytes, hash: Option<&'a Hash>, sequence_number_condition: Option, if_modified_since_condition: Option, @@ -23,12 +24,12 @@ impl<'a> UpdatePageBuilder<'a> { pub(crate) fn new( blob_client: &'a BlobClient, ba512_range: BA512Range, - content: &'a [u8], + content: impl Into, ) -> Self { Self { blob_client, ba512_range, - content, + content: content.into(), hash: None, sequence_number_condition: None, if_modified_since_condition: None, @@ -82,7 +83,7 @@ impl<'a> UpdatePageBuilder<'a> { request = add_optional_header_ref(&self.lease_id, request); request }, - Some(self.content), + Some(self.content.clone()), )?; trace!("request.headers() == {:#?}", request.headers()); diff --git a/sdk/storage/src/blob/container/requests/set_acl_builder.rs b/sdk/storage/src/blob/container/requests/set_acl_builder.rs index c5b422e52f..5ff1da33d9 100644 --- a/sdk/storage/src/blob/container/requests/set_acl_builder.rs +++ b/sdk/storage/src/blob/container/requests/set_acl_builder.rs @@ -5,6 +5,7 @@ use azure_core::headers::{add_mandatory_header, add_optional_header, add_optiona use azure_core::lease::LeaseId; use azure_core::prelude::*; use azure_core::StoredAccessPolicyList; +use bytes::Bytes; use http::method::Method; use http::status::StatusCode; @@ -62,7 +63,7 @@ impl<'a> SetACLBuilder<'a> { request }, match xml { - Some(ref x) => Some(x.as_bytes()), + Some(x) => Some(Bytes::from(x)), None => None, }, )?; diff --git a/sdk/storage/src/clients/blob_client.rs b/sdk/storage/src/clients/blob_client.rs index 0aa87d8f73..191e1c2b5d 100644 --- a/sdk/storage/src/clients/blob_client.rs +++ b/sdk/storage/src/clients/blob_client.rs @@ -5,6 +5,7 @@ use crate::shared_access_signature::SharedAccessSignature; use azure_core::errors::AzureError; use azure_core::prelude::*; use azure_core::HttpClient; +use bytes::Bytes; use http::method::Method; use http::request::{Builder, Request}; use std::sync::Arc; @@ -65,7 +66,7 @@ impl BlobClient { pub fn update_page<'a>( &'a self, ba512_range: BA512Range, - content: &'a [u8], + content: impl Into, ) -> UpdatePageBuilder<'a> { UpdatePageBuilder::new(self, ba512_range, content) } @@ -109,16 +110,20 @@ impl BlobClient { PutBlockListBuilder::new(self, block_list) } - pub fn put_block_blob<'a>(&'a self, body: &'a [u8]) -> PutBlockBlobBuilder<'a> { - PutBlockBlobBuilder::new(self, body) + pub fn put_block_blob<'a>(&'a self, body: impl Into) -> PutBlockBlobBuilder<'a> { + PutBlockBlobBuilder::new(self, body.into()) } - pub fn append_block<'a>(&'a self, body: &'a [u8]) -> AppendBlockBuilder<'a> { - AppendBlockBuilder::new(self, body) + pub fn append_block<'a>(&'a self, body: impl Into) -> AppendBlockBuilder<'a> { + AppendBlockBuilder::new(self, body.into()) } - pub fn put_block<'a>(&'a self, block_id: &'a BlockId, body: &'a [u8]) -> PutBlockBuilder<'a> { - PutBlockBuilder::new(self, block_id, body) + pub fn put_block<'a>( + &'a self, + block_id: &'a BlockId, + body: impl Into, + ) -> PutBlockBuilder<'a> { + PutBlockBuilder::new(self, block_id, body.into()) } pub fn clear_page(&self, ba512_range: BA512Range) -> ClearPageBuilder { @@ -153,8 +158,8 @@ impl BlobClient { url: &str, method: &Method, http_header_adder: &dyn Fn(Builder) -> Builder, - request_body: Option<&'a [u8]>, - ) -> Result<(Request<&'a [u8]>, url::Url), AzureError> { + request_body: Option, + ) -> Result<(Request, url::Url), AzureError> { self.container_client .prepare_request(url, method, http_header_adder, request_body) } diff --git a/sdk/storage/src/clients/blob_lease_client.rs b/sdk/storage/src/clients/blob_lease_client.rs index c11fac2d42..44be09ecb5 100644 --- a/sdk/storage/src/clients/blob_lease_client.rs +++ b/sdk/storage/src/clients/blob_lease_client.rs @@ -3,6 +3,7 @@ use crate::clients::{BlobClient, ContainerClient, StorageAccountClient}; use azure_core::errors::AzureError; use azure_core::prelude::*; use azure_core::HttpClient; +use bytes::Bytes; use http::method::Method; use http::request::{Builder, Request}; use std::sync::Arc; @@ -68,8 +69,8 @@ impl BlobLeaseClient { url: &str, method: &Method, http_header_adder: &dyn Fn(Builder) -> Builder, - request_body: Option<&'a [u8]>, - ) -> Result<(Request<&'a [u8]>, url::Url), AzureError> { + request_body: Option, + ) -> Result<(Request, url::Url), AzureError> { self.blob_client .prepare_request(url, method, http_header_adder, request_body) } diff --git a/sdk/storage/src/clients/container_client.rs b/sdk/storage/src/clients/container_client.rs index 9c794ddc7b..1964c70a13 100644 --- a/sdk/storage/src/clients/container_client.rs +++ b/sdk/storage/src/clients/container_client.rs @@ -3,6 +3,7 @@ use crate::clients::{StorageAccountClient, StorageClient}; use crate::container::requests::*; use azure_core::errors::AzureError; use azure_core::prelude::*; +use bytes::Bytes; use http::method::Method; use http::request::{Builder, Request}; use std::sync::Arc; @@ -87,8 +88,8 @@ impl ContainerClient { url: &str, method: &Method, http_header_adder: &dyn Fn(Builder) -> Builder, - request_body: Option<&'a [u8]>, - ) -> Result<(Request<&'a [u8]>, url::Url), AzureError> { + request_body: Option, + ) -> Result<(Request, url::Url), AzureError> { self.storage_client .prepare_request(url, method, http_header_adder, request_body) } diff --git a/sdk/storage/src/clients/container_lease_client.rs b/sdk/storage/src/clients/container_lease_client.rs index b43d5a5e02..efc4fd48ef 100644 --- a/sdk/storage/src/clients/container_lease_client.rs +++ b/sdk/storage/src/clients/container_lease_client.rs @@ -3,6 +3,7 @@ use crate::clients::{ContainerClient, StorageAccountClient}; use azure_core::errors::AzureError; use azure_core::prelude::*; use azure_core::HttpClient; +use bytes::Bytes; use http::method::Method; use http::request::{Builder, Request}; use std::sync::Arc; @@ -60,8 +61,8 @@ impl ContainerLeaseClient { url: &str, method: &Method, http_header_adder: &dyn Fn(Builder) -> Builder, - request_body: Option<&'a [u8]>, - ) -> Result<(Request<&'a [u8]>, url::Url), AzureError> { + request_body: Option, + ) -> Result<(Request, url::Url), AzureError> { self.container_client .prepare_request(url, method, http_header_adder, request_body) } diff --git a/sdk/storage/src/clients/storage_account_client.rs b/sdk/storage/src/clients/storage_account_client.rs index 5a71b2a0ae..741b0fb09d 100644 --- a/sdk/storage/src/clients/storage_account_client.rs +++ b/sdk/storage/src/clients/storage_account_client.rs @@ -5,6 +5,7 @@ use azure_core::headers::*; use azure_core::HttpClient; use azure_core::No; use azure_core::EMPTY_BODY; +use bytes::Bytes; use http::header::*; use http::method::Method; use http::request::{Builder, Request}; @@ -268,8 +269,8 @@ impl StorageAccountClient { method: &Method, http_header_adder: &dyn Fn(Builder) -> Builder, service_type: ServiceType, - request_body: Option<&'a [u8]>, - ) -> Result<(Request<&'a [u8]>, url::Url), AzureError> { + request_body: Option, + ) -> Result<(Request, url::Url), AzureError> { let dt = chrono::Utc::now(); let time = format!("{}", dt.format("%a, %d %h %Y %T GMT")); @@ -331,7 +332,7 @@ impl StorageAccountClient { let request = if let Some(request_body) = request_body { request.body(request_body) } else { - request.body(&EMPTY_BODY as &[u8]) + request.body(Bytes::from_static(EMPTY_BODY)) }?; debug!("using request == {:#?}", request); diff --git a/sdk/storage/src/clients/storage_client.rs b/sdk/storage/src/clients/storage_client.rs index f28d9ee8bb..41380dca52 100644 --- a/sdk/storage/src/clients/storage_client.rs +++ b/sdk/storage/src/clients/storage_client.rs @@ -1,5 +1,6 @@ use crate::clients::{ServiceType, StorageAccountClient}; use azure_core::errors::AzureError; +use bytes::Bytes; use http::method::Method; use http::request::{Builder, Request}; use std::sync::Arc; @@ -39,8 +40,8 @@ impl StorageClient { url: &str, method: &Method, http_header_adder: &dyn Fn(Builder) -> Builder, - request_body: Option<&'a [u8]>, - ) -> Result<(Request<&'a [u8]>, url::Url), AzureError> { + request_body: Option, + ) -> Result<(Request, url::Url), AzureError> { self.storage_account_client.prepare_request( url, method, diff --git a/sdk/storage/src/clients/table_client.rs b/sdk/storage/src/clients/table_client.rs index 8edaef9b22..1f08013476 100644 --- a/sdk/storage/src/clients/table_client.rs +++ b/sdk/storage/src/clients/table_client.rs @@ -1,6 +1,7 @@ use crate::clients::TableServiceClient; use crate::table::requests::*; use azure_core::errors::AzureError; +use bytes::Bytes; use http::method::Method; use http::request::{Builder, Request}; use std::sync::Arc; @@ -60,8 +61,8 @@ impl TableClient { url: &str, method: &Method, http_header_adder: &dyn Fn(Builder) -> Builder, - request_body: Option<&'a [u8]>, - ) -> Result<(Request<&'a [u8]>, url::Url), AzureError> { + request_body: Option, + ) -> Result<(Request, url::Url), AzureError> { self.table_service_client .prepare_request(url, method, http_header_adder, request_body) } diff --git a/sdk/storage/src/clients/table_service_client.rs b/sdk/storage/src/clients/table_service_client.rs index 2aa3e2ff56..ab401ab56b 100644 --- a/sdk/storage/src/clients/table_service_client.rs +++ b/sdk/storage/src/clients/table_service_client.rs @@ -1,6 +1,7 @@ use crate::clients::{ServiceType, StorageAccountClient}; use crate::table::requests::*; use azure_core::errors::AzureError; +use bytes::Bytes; use http::method::Method; use http::request::{Builder, Request}; use std::sync::Arc; @@ -40,8 +41,8 @@ impl TableServiceClient { url: &str, method: &Method, http_header_adder: &dyn Fn(Builder) -> Builder, - request_body: Option<&'a [u8]>, - ) -> Result<(Request<&'a [u8]>, url::Url), AzureError> { + request_body: Option, + ) -> Result<(Request, url::Url), AzureError> { self.storage_account_client.prepare_request( url, method, diff --git a/sdk/storage/src/table/requests/insert_entity_builder.rs b/sdk/storage/src/table/requests/insert_entity_builder.rs index 2585407dfd..e9591d6aef 100644 --- a/sdk/storage/src/table/requests/insert_entity_builder.rs +++ b/sdk/storage/src/table/requests/insert_entity_builder.rs @@ -2,6 +2,7 @@ use crate::clients::TableClient; use crate::table::requests::{PartitionKeyMissing, PartitionKeySet, RowKeyMissing, RowKeySet}; use azure_core::headers::add_optional_header; use azure_core::prelude::*; +use bytes::Bytes; use http::method::Method; use http::status::StatusCode; use serde::Serialize; @@ -127,7 +128,7 @@ where request = add_optional_header(&self.client_request_id, request); request }, - Some(json.as_bytes()), + Some(Bytes::from(json)), )?; println!("request == {:?}", request); diff --git a/sdk/storage/tests/stream_list_blobs.rs b/sdk/storage/tests/stream_list_blobs.rs index 9d5e02e002..c71c259b27 100644 --- a/sdk/storage/tests/stream_list_blobs.rs +++ b/sdk/storage/tests/stream_list_blobs.rs @@ -46,7 +46,7 @@ async fn stream_list_blobs() { for i in 0..10u8 { container .as_blob_client(format!("blob{}.txt", i)) - .put_block_blob("somedata".as_bytes()) + .put_block_blob("somedata") .content_type("text/plain") .execute() .await