Skip to content

Commit

Permalink
at the time of Pipeline::send, context doesn't need to be mutable (#1355
Browse files Browse the repository at this point in the history
)

* at the time of Pipeline::send, context doesn't need to be mutable

Up until we get to `Pipeline::send`, Context can (and likely will) be
mutable.  However, once we start processing the pipeline, it doesn't
need to be mutable anymore.  This is due to `Policy::send` not requiring
mutable context.

The changes to `azure_iot_hub` and `azure_security_keyvault` are related
to longer requiring mutable contexts once we get to `Policy::send`.

Ref: https://github.com/Azure/azure-sdk-for-rust/blob/43d4e9974060e78bbd8912ddcc183567781997fc/sdk/core/src/policies/mod.rs#L30-L33
  • Loading branch information
demoray authored Sep 8, 2023
1 parent 73e9938 commit f704e9a
Show file tree
Hide file tree
Showing 947 changed files with 1,891 additions and 1,907 deletions.
2 changes: 1 addition & 1 deletion sdk/core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Pipeline {
&self.pipeline
}

pub async fn send(&self, ctx: &mut Context, request: &mut Request) -> crate::Result<Response> {
pub async fn send(&self, ctx: &Context, request: &mut Request) -> crate::Result<Response> {
self.pipeline[0]
.send(ctx, request, &self.pipeline[1..])
.await
Expand Down
2 changes: 1 addition & 1 deletion sdk/iot_hub/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ impl ServiceClient {
/// send the request via the request pipeline
pub async fn send(
&self,
context: &mut Context,
context: &Context,
request: &mut Request,
) -> azure_core::Result<Response> {
self.pipeline.send(context, request).await
Expand Down
4 changes: 2 additions & 2 deletions sdk/iot_hub/src/service/operations/apply_on_edge_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ operation! {

impl ApplyOnEdgeDeviceBuilder {
/// Performs the apply on edge device request
pub fn into_future(mut self) -> ApplyOnEdgeDevice {
pub fn into_future(self) -> ApplyOnEdgeDevice {
Box::pin(async move {
let uri = format!(
"https://{}.azure-devices.net/devices/{}/applyConfigurationContent?api-version={}",
Expand All @@ -32,7 +32,7 @@ impl ApplyOnEdgeDeviceBuilder {
let body = azure_core::to_json(&body)?;
request.set_body(body);

self.client.send(&mut self.context, &mut request).await?;
self.client.send(&self.context, &mut request).await?;

Ok(())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl CreateOrUpdateConfigurationBuilder {
}

/// Performs the create or update request on the device identity
pub fn into_future(mut self) -> CreateOrUpdateConfiguration {
pub fn into_future(self) -> CreateOrUpdateConfiguration {
Box::pin(async move {
let uri = format!(
"https://{}.azure-devices.net/configurations/{}?api-version={}",
Expand Down Expand Up @@ -101,7 +101,7 @@ impl CreateOrUpdateConfigurationBuilder {
let body = azure_core::to_json(&body)?;
request.set_body(body);

let response = self.client.send(&mut self.context, &mut request).await?;
let response = self.client.send(&self.context, &mut request).await?;

CreateOrUpdateConfigurationResponse::try_from(response).await
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl CreateOrUpdateDeviceIdentityBuilder {
}

/// Performs the create or update request on the device identity
pub fn into_future(mut self) -> CreateOrUpdateDeviceIdentity {
pub fn into_future(self) -> CreateOrUpdateDeviceIdentity {
Box::pin(async move {
let uri = format!(
"https://{}.azure-devices.net/devices/{}?api-version={}",
Expand Down Expand Up @@ -66,7 +66,7 @@ impl CreateOrUpdateDeviceIdentityBuilder {
let body = azure_core::to_json(&body)?;
request.set_body(body);

let response = self.client.send(&mut self.context, &mut request).await?;
let response = self.client.send(&self.context, &mut request).await?;

CreateOrUpdateDeviceIdentityResponse::try_from(response).await
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ azure_core::operation! {

impl CreateOrUpdateModuleIdentityBuilder {
/// Performs the create or update request on the device identity
pub fn into_future(mut self) -> CreateOrUpdateModuleIdentity {
pub fn into_future(self) -> CreateOrUpdateModuleIdentity {
Box::pin(async move {
let uri = format!(
"https://{}.azure-devices.net/devices/{}/modules/{}?api-version={}",
Expand Down Expand Up @@ -50,7 +50,7 @@ impl CreateOrUpdateModuleIdentityBuilder {
let body = azure_core::to_json(&body)?;
request.set_body(body);

let response = self.client.send(&mut self.context, &mut request).await?;
let response = self.client.send(&self.context, &mut request).await?;

CreateOrUpdateModuleIdentityResponse::try_from(response).await
})
Expand Down
4 changes: 2 additions & 2 deletions sdk/iot_hub/src/service/operations/delete_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ azure_core::operation! {

impl DeleteConfigurationBuilder {
/// Execute the request to delete the configuration.
pub fn into_future(mut self) -> DeleteConfiguration {
pub fn into_future(self) -> DeleteConfiguration {
Box::pin(async move {
let uri = format!(
"https://{}.azure-devices.net/configurations/{}?api-version={}",
Expand All @@ -25,7 +25,7 @@ impl DeleteConfigurationBuilder {

request.set_body(azure_core::EMPTY_BODY);

self.client.send(&mut self.context, &mut request).await?;
self.client.send(&self.context, &mut request).await?;

Ok(())
})
Expand Down
4 changes: 2 additions & 2 deletions sdk/iot_hub/src/service/operations/delete_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ azure_core::operation! {

impl DeleteIdentityBuilder {
/// Execute the request to delete the module or device identity.
pub fn into_future(mut self) -> DeleteIdentity {
pub fn into_future(self) -> DeleteIdentity {
Box::pin(async move {
let uri = match &self.module_id {
Some(module_id) => format!(
Expand All @@ -31,7 +31,7 @@ impl DeleteIdentityBuilder {

request.set_body(azure_core::EMPTY_BODY);

self.client.send(&mut self.context, &mut request).await?;
self.client.send(&self.context, &mut request).await?;
Ok(())
})
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/iot_hub/src/service/operations/get_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ azure_core::operation! {

impl GetConfigurationBuilder {
/// Execute the request to get the configuration of a given identifier.
pub fn into_future(mut self) -> GetConfiguration {
pub fn into_future(self) -> GetConfiguration {
Box::pin(async move {
let uri = match self.configuration_id {
Some(val) => format!(
Expand All @@ -28,7 +28,7 @@ impl GetConfigurationBuilder {
let mut request = self.client.finalize_request(&uri, Method::Get)?;
request.set_body(azure_core::EMPTY_BODY);

let response = self.client.send(&mut self.context, &mut request).await?;
let response = self.client.send(&self.context, &mut request).await?;

GetConfigurationResponse::try_from(response).await
})
Expand Down
4 changes: 2 additions & 2 deletions sdk/iot_hub/src/service/operations/get_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ azure_core::operation! {

impl GetIdentityBuilder {
/// Execute the request to get the identity of a device or module.
pub fn into_future(mut self) -> GetIdentity {
pub fn into_future(self) -> GetIdentity {
Box::pin(async move {
let uri = match self.module_id {
Some(module_id) => format!(
Expand All @@ -27,7 +27,7 @@ impl GetIdentityBuilder {
let mut request = self.client.finalize_request(&uri, Method::Get)?;
request.set_body(azure_core::EMPTY_BODY);

let response = self.client.send(&mut self.context, &mut request).await?;
let response = self.client.send(&self.context, &mut request).await?;

GetIdentityResponse::from_response(response).await
})
Expand Down
4 changes: 2 additions & 2 deletions sdk/iot_hub/src/service/operations/get_twin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ azure_core::operation! {

impl GetTwinBuilder {
/// Execute the request to get the twin of a module or device.
pub fn into_future(mut self) -> GetTwin {
pub fn into_future(self) -> GetTwin {
Box::pin(async move {
let uri = match self.module_id {
Some(val) => format!(
Expand All @@ -27,7 +27,7 @@ impl GetTwinBuilder {
let mut request = self.client.finalize_request(&uri, Method::Get)?;
request.set_body(azure_core::EMPTY_BODY);

let response = self.client.send(&mut self.context, &mut request).await?;
let response = self.client.send(&self.context, &mut request).await?;

GetTwinResponse::from_response(response).await
})
Expand Down
4 changes: 2 additions & 2 deletions sdk/iot_hub/src/service/operations/invoke_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ azure_core::operation! {

impl InvokeMethodBuilder {
/// Turn the builder into a `Future`
pub fn into_future(mut self) -> InvokeMethod {
pub fn into_future(self) -> InvokeMethod {
Box::pin(async move {
let uri = match &self.module_id {
Some(module_id_value) => format!(
Expand All @@ -43,7 +43,7 @@ impl InvokeMethodBuilder {

request.set_body(body);

let response = self.client.send(&mut self.context, &mut request).await?;
let response = self.client.send(&self.context, &mut request).await?;

InvokeMethodResponse::try_from(response).await
})
Expand Down
4 changes: 2 additions & 2 deletions sdk/iot_hub/src/service/operations/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ azure_core::operation! {

impl QueryBuilder {
/// Invoke a qiven query on the `IoT` Hub
pub fn into_future(mut self) -> Query {
pub fn into_future(self) -> Query {
Box::pin(async move {
let uri = format!(
"https://{}.azure-devices.net/devices/query?api-version={}",
Expand All @@ -37,7 +37,7 @@ impl QueryBuilder {
request.add_mandatory_header(&self.max_item_count.unwrap_or_default());
request.set_body(body);

let response = self.client.send(&mut self.context, &mut request).await?;
let response = self.client.send(&self.context, &mut request).await?;

QueryResponse::try_from(response).await
})
Expand Down
4 changes: 2 additions & 2 deletions sdk/iot_hub/src/service/operations/update_or_replace_twin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl UpdateOrReplaceTwinBuilder {
/// .desired_properties(serde_json::json!({"PropertyName": "PropertyValue"}))
/// ;
/// ```
pub fn into_future(mut self) -> UpdateOrReplaceTwin {
pub fn into_future(self) -> UpdateOrReplaceTwin {
Box::pin(async move {
let body = DesiredTwinBody {
tags: self.desired_tags.unwrap_or_default(),
Expand Down Expand Up @@ -84,7 +84,7 @@ impl UpdateOrReplaceTwinBuilder {

request.set_body(body);

let response = self.client.send(&mut self.context, &mut request).await?;
let response = self.client.send(&self.context, &mut request).await?;

UpdateOrReplaceTwinResponse::from_response(response).await
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl ListCertificatesBuilder {
pub fn into_stream(self) -> Pageable<KeyVaultGetCertificatesResponse, Error> {
let make_request = move |continuation: Option<String>| {
let this = self.clone();
let mut ctx = self.context.clone();
let ctx = self.context.clone();
async move {
let mut uri = this.client.keyvault_client.vault_url.clone();
uri.set_path("certificates");
Expand All @@ -31,11 +31,7 @@ impl ListCertificatesBuilder {
None,
)?;

let response = this
.client
.keyvault_client
.send(&mut ctx, &mut request)
.await?;
let response = this.client.keyvault_client.send(&ctx, &mut request).await?;

let response = CollectedResponse::from_response(response).await?;
let body = response.body();
Expand Down
8 changes: 2 additions & 6 deletions sdk/security_keyvault/src/account/operations/list_secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl ListSecretsBuilder {
pub fn into_stream(self) -> Pageable<KeyVaultGetSecretsResponse, Error> {
let make_request = move |continuation: Option<String>| {
let this = self.clone();
let mut ctx = self.context.clone();
let ctx = self.context.clone();
async move {
let mut uri = this.client.keyvault_client.vault_url.clone();
uri.set_path("secrets");
Expand All @@ -31,11 +31,7 @@ impl ListSecretsBuilder {
None,
)?;

let response = this
.client
.keyvault_client
.send(&mut ctx, &mut request)
.await?;
let response = this.client.keyvault_client.send(&ctx, &mut request).await?;

let response = CollectedResponse::from_response(response).await?;
let body = response.body();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ operation! {
}

impl RestoreCertificateBuilder {
pub fn into_future(mut self) -> RestoreCertificate {
pub fn into_future(self) -> RestoreCertificate {
Box::pin(async move {
let mut uri = self.client.keyvault_client.vault_url.clone();
uri.set_path("certificates/restore");
Expand All @@ -26,7 +26,7 @@ impl RestoreCertificateBuilder {

self.client
.keyvault_client
.send(&mut self.context, &mut request)
.send(&self.context, &mut request)
.await?;

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ operation! {
}

impl RestoreSecretBuilder {
pub fn into_future(mut self) -> RestoreSecret {
pub fn into_future(self) -> RestoreSecret {
Box::pin(async move {
let mut uri = self.client.keyvault_client.vault_url.clone();
uri.set_path("secrets/restore");
Expand All @@ -26,7 +26,7 @@ impl RestoreSecretBuilder {

self.client
.keyvault_client
.send(&mut self.context, &mut request)
.send(&self.context, &mut request)
.await?;

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions sdk/security_keyvault/src/certificates/operations/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ operation! {
}

impl CertificateBackupBuilder {
pub fn into_future(mut self) -> CertificateBackup {
pub fn into_future(self) -> CertificateBackup {
Box::pin(async move {
let mut uri = self.client.keyvault_client.vault_url.clone();
uri.set_path(&format!("certificates/{}/backup", self.name));
Expand All @@ -22,7 +22,7 @@ impl CertificateBackupBuilder {
let response = self
.client
.keyvault_client
.send(&mut self.context, &mut request)
.send(&self.context, &mut request)
.await?;

let response = CollectedResponse::from_response(response).await?;
Expand Down
4 changes: 2 additions & 2 deletions sdk/security_keyvault/src/certificates/operations/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub enum JsonWebKeyType {
}

impl CreateCertificateBuilder {
pub fn into_future(mut self) -> CreateCertificate {
pub fn into_future(self) -> CreateCertificate {
Box::pin(async move {
let mut uri = self.client.keyvault_client.vault_url.clone();
uri.set_path(&format!("certificates/{}/create", self.name));
Expand Down Expand Up @@ -140,7 +140,7 @@ impl CreateCertificateBuilder {
let response = self
.client
.keyvault_client
.send(&mut self.context, &mut request)
.send(&self.context, &mut request)
.await?;

let response = CollectedResponse::from_response(response).await?;
Expand Down
4 changes: 2 additions & 2 deletions sdk/security_keyvault/src/certificates/operations/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ operation! {
}

impl DeleteCertificateBuilder {
pub fn into_future(mut self) -> DeleteCertificate {
pub fn into_future(self) -> DeleteCertificate {
Box::pin(async move {
let mut uri = self.client.keyvault_client.vault_url.clone();
uri.set_path(&format!("certificates/{}", self.name));
Expand All @@ -22,7 +22,7 @@ impl DeleteCertificateBuilder {
let response = self
.client
.keyvault_client
.send(&mut self.context, &mut request)
.send(&self.context, &mut request)
.await?;

let response = CollectedResponse::from_response(response).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ operation! {
}

impl DeleteCertificateOperationBuilder {
pub fn into_future(mut self) -> DeleteCertificateOperation {
pub fn into_future(self) -> DeleteCertificateOperation {
Box::pin(async move {
let mut uri = self.client.keyvault_client.vault_url.clone();
uri.set_path(&format!("certificates/{}/pending", self.name));
Expand All @@ -22,7 +22,7 @@ impl DeleteCertificateOperationBuilder {
let response = self
.client
.keyvault_client
.send(&mut self.context, &mut request)
.send(&self.context, &mut request)
.await?;

let response = CollectedResponse::from_response(response).await?;
Expand Down
Loading

0 comments on commit f704e9a

Please sign in to comment.