Skip to content

Commit

Permalink
move storage core to use operations macro (#917)
Browse files Browse the repository at this point in the history
Co-authored-by: Brian Caswell <[email protected]>
Co-authored-by: Ryan Levick <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2022
1 parent dfe7d5b commit 2671ca1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 70 deletions.
47 changes: 7 additions & 40 deletions sdk/storage/src/account/operations/find_blobs_by_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,15 @@ use azure_core::prelude::*;
use azure_core::{collect_pinned_stream, RequestId, Response as HttpResponse};
use chrono::{DateTime, Utc};

#[derive(Debug, Clone)]
pub struct FindBlobsByTagsBuilder {
operation! {
FindBlobsByTags,
client: StorageClient,
expression: String,
#[allow(unused)]
next_marker: Option<NextMarker>,
#[allow(unused)]
max_results: Option<MaxResults>,
context: Context,
?next_marker: NextMarker,
?max_results: MaxResults
}

impl FindBlobsByTagsBuilder {
pub(crate) fn new(client: StorageClient) -> Self {
Self {
client,
expression: String::new(),
next_marker: None,
max_results: None,
context: Context::new(),
}
}

setters! {
expression: String => expression,
next_marker: NextMarker => Some(next_marker),
max_results: MaxResults => Some(max_results),
context: Context => context,
}

// TODO: Make this a stream instead of a `Future`
pub fn into_future(mut self) -> FindBlobsByTags {
Box::pin(async move {
Expand All @@ -52,26 +32,13 @@ impl FindBlobsByTagsBuilder {
.send(&mut self.context, &mut request, ServiceType::Blob)
.await?;

ListBlobsByTagsResponse::try_from(response).await
FindBlobsByTagsResponse::try_from(response).await
})
}
}

/// The future returned by calling `into_future` on the builder.
pub type FindBlobsByTags =
futures::future::BoxFuture<'static, azure_core::Result<ListBlobsByTagsResponse>>;

#[cfg(feature = "into_future")]
impl std::future::IntoFuture for FindBlobsByTagsBuilder {
type IntoFuture = FindBlobsByTags;
type Output = <FindBlobsByTags as std::future::Future>::Output;
fn into_future(self) -> Self::IntoFuture {
Self::into_future(self)
}
}

#[derive(Debug, Clone, PartialEq)]
pub struct ListBlobsByTagsResponse {
pub struct FindBlobsByTagsResponse {
pub max_results: Option<u32>,
pub delimiter: Option<String>,
pub next_marker: Option<NextMarker>,
Expand Down Expand Up @@ -106,7 +73,7 @@ pub struct Blob {
pub tag_value: String,
}

impl ListBlobsByTagsResponse {
impl FindBlobsByTagsResponse {
async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let (_status_code, headers, pinned_stream) = response.deconstruct();
let body = collect_pinned_stream(pinned_stream).await?;
Expand Down
31 changes: 3 additions & 28 deletions sdk/storage/src/account/operations/get_account_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,15 @@ use azure_core::headers::{
account_kind_from_headers, date_from_headers, request_id_from_headers, sku_name_from_headers,
Headers,
};
use azure_core::{Context, RequestId};
use azure_core::RequestId;
use chrono::{DateTime, Utc};

#[derive(Debug, Clone)]
pub struct GetAccountInformationBuilder {
operation! {
GetAccountInformation,
client: StorageClient,
context: Context,
}

impl GetAccountInformationBuilder {
pub(crate) fn new(client: StorageClient) -> Self {
Self {
client,
context: Context::new(),
}
}

setters! {
context: Context => context,
}

pub fn into_future(mut self) -> GetAccountInformation {
Box::pin(async move {
let mut request = self.client.blob_storage_request(azure_core::Method::Get)?;
Expand All @@ -43,19 +31,6 @@ impl GetAccountInformationBuilder {
}
}

/// The future returned by calling `into_future` on the builder.
pub type GetAccountInformation =
futures::future::BoxFuture<'static, azure_core::Result<GetAccountInformationResponse>>;

#[cfg(feature = "into_future")]
impl std::future::IntoFuture for GetAccountInformationBuilder {
type IntoFuture = GetAccountInformation;
type Output = <GetAccountInformation as std::future::Future>::Output;
fn into_future(self) -> Self::IntoFuture {
Self::into_future(self)
}
}

#[derive(Debug, Clone)]
pub struct GetAccountInformationResponse {
pub request_id: RequestId,
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/src/core/clients/storage_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ impl StorageClient {
GetAccountInformationBuilder::new(self.clone())
}

pub fn find_blobs_by_tags(&self) -> FindBlobsByTagsBuilder {
FindBlobsByTagsBuilder::new(self.clone())
pub fn find_blobs_by_tags(&self, expression: String) -> FindBlobsByTagsBuilder {
FindBlobsByTagsBuilder::new(self.clone(), expression)
}

fn url_with_segments<'a, I>(mut url: url::Url, new_segments: I) -> azure_core::Result<url::Url>
Expand Down

0 comments on commit 2671ca1

Please sign in to comment.