-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codegen helper for defining operation-specific `CustomizableOpera…
…tion` methods. (#3918) This PR lays the groundwork for defining operation-specific `CustomizableOperation` methods. ## Codegen Example If we were to define pre-signable ops this way, code like the following would be emitted for each op that supported presigning. ```rust impl<E, B> CustomizableOperation<crate::operation::put_object::PutObject, E, B> { /// Sends the request and returns the response. #[allow(unused_mut)] pub async fn presigned( mut self, presigning_config: crate::presigning::PresigningConfig, ) -> ::std::result::Result<crate::presigning::PresignedRequest, crate::error::SdkError<E>> where E: std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static, B: crate::client::customize::internal::CustomizablePresigned<E>, { self.execute(move |sender, conf| sender.presign(conf, presigning_config)).await } } ``` _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
- Loading branch information
Showing
4 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationImplGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.client.smithy.generators.client | ||
|
||
import software.amazon.smithy.model.shapes.OperationShape | ||
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationCustomization | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationSection | ||
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter | ||
import software.amazon.smithy.rust.codegen.core.rustlang.rust | ||
import software.amazon.smithy.rust.codegen.core.smithy.customize.allCustomizationsAreEmpty | ||
import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations | ||
|
||
class CustomizableOperationImplGenerator( | ||
private val codegenContext: ClientCodegenContext, | ||
private val operation: OperationShape, | ||
private val customizations: List<OperationCustomization>, | ||
) { | ||
fun render(writer: RustWriter) { | ||
val section = OperationSection.CustomizableOperationImpl(customizations, operation) | ||
// When no customizations are set or there is nothing to write, return early. | ||
if (customizations.isEmpty() || allCustomizationsAreEmpty(customizations, section)) { | ||
return | ||
} | ||
|
||
writer.rust("impl<E, B> CustomizableOperation<#T, E, B> {", codegenContext.symbolProvider.toSymbol(operation)) | ||
writer.writeCustomizations(customizations, section) | ||
writer.rust("}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters