From d3c6db091075da4a11473bb03e374f8cde83093b Mon Sep 17 00:00:00 2001 From: 82marbag <69267416+82marbag@users.noreply.github.com> Date: Fri, 16 Sep 2022 10:06:23 +0200 Subject: [PATCH] Address comments Signed-off-by: Daniele Ahmed --- .../smithy/generators/ServerServiceGeneratorV2.kt | 15 ++++++++------- .../examples/pokemon-service/tests/helpers.rs | 2 +- .../src/operation/upgrade.rs | 4 ++-- rust-runtime/aws-smithy-http-server/src/plugin.rs | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt index c97618ae52..68e7e2ca85 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt @@ -64,7 +64,7 @@ class ServerServiceGeneratorV2( /** A `Writable` block containing all the `Handler` and `Operation` setters for the builder. */ private fun builderSetters(): Writable = writable { - val pluginType = listOf("Plugin") + val pluginType = listOf("Pl") for ((index, pair) in builderFieldNames.zip(operationStructNames).withIndex()) { val (fieldName, structName) = pair @@ -161,7 +161,7 @@ class ServerServiceGeneratorV2( crate::operation_shape::${symbolProvider.toSymbol(operation).name.toPascalCase()}, $exts, B, - Plugin, + Pl, >, $type::Service: Clone + Send + 'static, <$type::Service as #{Tower}::Service<#{Http}::Request>>::Future: Send + 'static, @@ -177,8 +177,9 @@ class ServerServiceGeneratorV2( /** Returns a `Writable` containing the builder struct definition and its implementations. */ private fun builder(): Writable = writable { val extensionTypesDefault = extensionTypes.map { "$it = ()" } - val pluginName = "Plugin" + val pluginName = "Pl" val pluginTypeList = listOf(pluginName) + val newPluginType = "New$pluginName" val pluginTypeDefault = listOf("$pluginName = #{SmithyHttpServer}::plugin::IdentityPlugin") val structGenerics = (builderOps + extensionTypesDefault + pluginTypeDefault).joinToString(", ") val builderGenerics = (builderOps + extensionTypes + pluginTypeList).joinToString(", ") @@ -205,7 +206,7 @@ class ServerServiceGeneratorV2( ${builderFields.joinToString(", ")}, ##[allow(unused_parens)] _exts: std::marker::PhantomData<(${extensionTypes.joinToString(", ")})>, - plugin: Plugin, + plugin: $pluginName, } impl<$builderGenerics> $builderName<$builderGenerics> { @@ -225,9 +226,9 @@ class ServerServiceGeneratorV2( } } - impl<$builderGenerics, NewPlugin> #{SmithyHttpServer}::plugin::Pluggable for $builderName<$builderGenerics> { - type Output = $builderName<$builderGenericsNoPlugin, aws_smithy_http_server::plugin::PluginStack<$pluginName, NewPlugin>>; - fn apply(self, plugin: NewPlugin) -> Self::Output { + impl<$builderGenerics, $newPluginType> #{SmithyHttpServer}::plugin::Pluggable<$newPluginType> for $builderName<$builderGenerics> { + type Output = $builderName<$builderGenericsNoPlugin, #{SmithyHttpServer}::plugin::PluginStack<$pluginName, $newPluginType>>; + fn apply(self, plugin: $newPluginType) -> Self::Output { $builderName { $setterFields, _exts: self._exts, diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/tests/helpers.rs b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/tests/helpers.rs index 0aec3b4d3e..62322ba085 100644 --- a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/tests/helpers.rs +++ b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/tests/helpers.rs @@ -34,7 +34,7 @@ impl PokemonServiceVariant { }; // Give PokémonService some time to start up. - time::sleep(Duration::from_millis(1000)).await; + time::sleep(Duration::from_millis(500)).await; process } diff --git a/rust-runtime/aws-smithy-http-server/src/operation/upgrade.rs b/rust-runtime/aws-smithy-http-server/src/operation/upgrade.rs index d093f66138..5028231e21 100644 --- a/rust-runtime/aws-smithy-http-server/src/operation/upgrade.rs +++ b/rust-runtime/aws-smithy-http-server/src/operation/upgrade.rs @@ -279,13 +279,13 @@ pub struct MissingOperation; /// This _does_ implement [`Upgradable`] but produces a [`Service`] which always returns an internal failure message. pub struct FailOnMissingOperation; -impl Upgradable for FailOnMissingOperation +impl Upgradable for FailOnMissingOperation where InternalFailureException: IntoResponse

, { type Service = MissingFailure

; - fn upgrade(self, _plugin: &Plugin) -> Self::Service { + fn upgrade(self, _plugin: &Pl) -> Self::Service { MissingFailure { _protocol: PhantomData } } } diff --git a/rust-runtime/aws-smithy-http-server/src/plugin.rs b/rust-runtime/aws-smithy-http-server/src/plugin.rs index 3636243e77..ff20a5758d 100644 --- a/rust-runtime/aws-smithy-http-server/src/plugin.rs +++ b/rust-runtime/aws-smithy-http-server/src/plugin.rs @@ -13,7 +13,7 @@ use crate::operation::Operation; /// /// ``` /// # struct PrintPlugin; -/// # use crate::plugin::Pluggable; +/// # use aws_smithy_http_server::plugin::Pluggable; /// trait PrintExt: Pluggable { /// fn print(self) -> Self::Output { /// self.apply(&PrintPlugin); @@ -29,7 +29,7 @@ pub trait Pluggable { } /// Maps one [`Operation`] to another, -/// parameterised by the protocol P and operation shape Op to allow for plugin behaviour to be specialised accordingly. +/// parameterised by the protocol `P` and operation shape `Op` to allow for plugin behaviour to be specialised accordingly. /// /// This is passed to [`Pluggable::apply`] to modify the behaviour of the builder. pub trait Plugin {