Skip to content

Commit

Permalink
Unstable serde support (#11)
Browse files Browse the repository at this point in the history
* add line (smithy-lang#2311)

* RFC30/Set fields to fluent builder (smithy-lang#2310)

* fn set_fields

* add fn set_fields to fluent builder

* better docs

* fix

* improve document
cfg to Attribute class
  • Loading branch information
thomas-k-cameron authored Mar 5, 2023
1 parent 670b873 commit cbd1958
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/RustBuildTool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private fun runCli(
}
}
.copyTo(action)
action.environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
action.execute()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ class FluentClientGenerator(
) {
val outputType = symbolProvider.toSymbol(operation.outputShape(model))
val errorType = operation.errorSymbol(symbolProvider)

val operationFnName = clientOperationFnName(
operation,
symbolProvider,
)
// Have to use fully-qualified result here or else it could conflict with an op named Result
rustTemplate(
"""
Expand All @@ -287,6 +290,18 @@ class FluentClientGenerator(
Ok(crate::operation::customize::CustomizableOperation { handle, operation })
}
##[#{Unstable}]
/// This function replaces the parameter with new one.
/// It is useful when you want to replace the existing data with de-serialized data.
/// ```rust
/// let deserialized_parameters: #{InputBuilderType} = serde_json::from_str(parameters_written_in_json).unwrap();
/// let outcome: #{OperationOutput} = client.$operationFnName().set_fields(&deserialized_parameters).send().await;
/// ```
pub fn set_fields(mut self, data: #{InputBuilderType}) -> Self {
self.inner = data;
self
}
/// Sends the request and returns the response.
///
/// If an error occurs, an `SdkError` will be returned with additional details that
Expand All @@ -304,6 +319,8 @@ class FluentClientGenerator(
self.handle.client.call(op).await
}
""",
"Unstable" to Attribute.AwsSdkUnstableAttribute.inner,
"InputBuilderType" to input.builderSymbol(symbolProvider),
"ClassifyRetry" to RuntimeType.classifyRetry(runtimeConfig),
"OperationError" to errorType,
"OperationOutput" to outputType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ class Attribute(val inner: Writable) {

val Test = Attribute("test")
val TokioTest = Attribute(RuntimeType.Tokio.resolve("test").writable)
val AwsSdkUnstableAttribute = Attribute(cfg("aws_sdk_unstable"))

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

0 comments on commit cbd1958

Please sign in to comment.