Skip to content

Commit 35cd929

Browse files
RFC30/Set fields to fluent builder (#2310)
* fn set_fields * add fn set_fields to fluent builder * better docs * fix * improve document cfg to Attribute class
1 parent 46280e4 commit 35cd929

File tree

2 files changed

+19
-1
lines changed
  • codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client
  • codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang

2 files changed

+19
-1
lines changed

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ class FluentClientGenerator(
264264
) {
265265
val outputType = symbolProvider.toSymbol(operation.outputShape(model))
266266
val errorType = operation.errorSymbol(symbolProvider)
267-
267+
val operationFnName = clientOperationFnName(
268+
operation,
269+
symbolProvider,
270+
)
268271
// Have to use fully-qualified result here or else it could conflict with an op named Result
269272
rustTemplate(
270273
"""
@@ -287,6 +290,18 @@ class FluentClientGenerator(
287290
Ok(crate::operation::customize::CustomizableOperation { handle, operation })
288291
}
289292
293+
##[#{Unstable}]
294+
/// This function replaces the parameter with new one.
295+
/// It is useful when you want to replace the existing data with de-serialized data.
296+
/// ```rust
297+
/// let deserialized_parameters: #{InputBuilderType} = serde_json::from_str(parameters_written_in_json).unwrap();
298+
/// let outcome: #{OperationOutput} = client.$operationFnName().set_fields(&deserialized_parameters).send().await;
299+
/// ```
300+
pub fn set_fields(mut self, data: #{InputBuilderType}) -> Self {
301+
self.inner = data;
302+
self
303+
}
304+
290305
/// Sends the request and returns the response.
291306
///
292307
/// If an error occurs, an `SdkError` will be returned with additional details that
@@ -304,6 +319,8 @@ class FluentClientGenerator(
304319
self.handle.client.call(op).await
305320
}
306321
""",
322+
"Unstable" to Attribute.AwsSdkUnstableAttribute.inner,
323+
"InputBuilderType" to input.builderSymbol(symbolProvider),
307324
"ClassifyRetry" to RuntimeType.classifyRetry(runtimeConfig),
308325
"OperationError" to errorType,
309326
"OperationOutput" to outputType,

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ class Attribute(val inner: Writable) {
470470

471471
val Test = Attribute("test")
472472
val TokioTest = Attribute(RuntimeType.Tokio.resolve("test").writable)
473+
val AwsSdkUnstableAttribute = Attribute(cfg("aws_sdk_unstable"))
473474

474475
/**
475476
* [non_exhaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute)

0 commit comments

Comments
 (0)