From bec93c8a5ec4b1423765d4e9f0c9317ae624a149 Mon Sep 17 00:00:00 2001 From: Harry Barber <106155934+hlbarber@users.noreply.github.com> Date: Wed, 8 Mar 2023 15:56:56 +0000 Subject: [PATCH] Remove uncessary type parameter and constraints from `Upgrade` service (#2436) * Remove B from Upgrade service * Remove duplicated bounds on Upgradable * Update documentation * Add CHANGELOG.next.toml entry --- CHANGELOG.next.toml | 6 +++ design/src/server/anatomy.md | 2 +- .../src/operation/upgrade.rs | 40 +++++++------------ 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 5317cd5c7..0f769a2a2 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -239,3 +239,9 @@ message = "`SdkError` variants can now be constructed for easier unit testing." references = ["smithy-rs#2428", "smithy-rs#2208"] meta = { "breaking" = false, "tada" = true, "bug" = false, "target" = "client" } author = "jdisanti" + +[[smithy-rs]] +message = "Remove unnecessary type parameter `B` from `Upgrade` service." +references = ["smithy-rs#2436"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } +author = "hlbarber" diff --git a/design/src/server/anatomy.md b/design/src/server/anatomy.md index 794239d3b..394a05716 100644 --- a/design/src/server/anatomy.md +++ b/design/src/server/anatomy.md @@ -301,7 +301,7 @@ where When we `GetPokemonService::from_handler` or `GetPokemonService::from_service`, the model service produced, `S`, will meet the constraints above. -There is an associated `Layer`, `UpgradeLayer` which constructs `Upgrade` from a service. +There is an associated `Layer`, `UpgradeLayer` which constructs `Upgrade` from a service. The upgrade procedure is finalized by the application of the `Layer` `L`, referenced in `Operation`. In this way the entire upgrade procedure takes an `Operation` and returns a HTTP service. 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 cc38466c8..61e550ce8 100644 --- a/rust-runtime/aws-smithy-http-server/src/operation/upgrade.rs +++ b/rust-runtime/aws-smithy-http-server/src/operation/upgrade.rs @@ -32,39 +32,36 @@ use super::{Operation, OperationError, OperationShape}; /// /// See [`Upgrade`]. #[derive(Debug, Clone)] -pub struct UpgradeLayer { +pub struct UpgradeLayer { _protocol: PhantomData, _operation: PhantomData, _exts: PhantomData, - _body: PhantomData, } -impl Default for UpgradeLayer { +impl Default for UpgradeLayer { fn default() -> Self { Self { _protocol: PhantomData, _operation: PhantomData, _exts: PhantomData, - _body: PhantomData, } } } -impl UpgradeLayer { +impl UpgradeLayer { /// Creates a new [`UpgradeLayer`]. pub fn new() -> Self { Self::default() } } -impl Layer for UpgradeLayer { - type Service = Upgrade; +impl Layer for UpgradeLayer { + type Service = Upgrade; fn layer(&self, inner: S) -> Self::Service { Upgrade { _protocol: PhantomData, _operation: PhantomData, - _body: PhantomData, _exts: PhantomData, inner, } @@ -73,15 +70,14 @@ impl Layer for UpgradeLayer { /// A [`Service`] responsible for wrapping an operation [`Service`] accepting and returning Smithy /// types, and converting it into a [`Service`] accepting and returning [`http`] types. -pub struct Upgrade { +pub struct Upgrade { _protocol: PhantomData, _operation: PhantomData, _exts: PhantomData, - _body: PhantomData, inner: S, } -impl Clone for Upgrade +impl Clone for Upgrade where S: Clone, { @@ -89,7 +85,6 @@ where Self { _protocol: PhantomData, _operation: PhantomData, - _body: PhantomData, _exts: PhantomData, inner: self.inner.clone(), } @@ -177,7 +172,7 @@ where } } -impl Service> for Upgrade +impl Service> for Upgrade where // `Op` is used to specify the operation shape Op: OperationShape, @@ -225,9 +220,8 @@ pub trait Upgradable { fn upgrade(self, plugin: &Plugin) -> Route; } -type UpgradedService = <>::Layer as Layer< - Upgrade>::Service>, ->>::Service; +type UpgradedService = + <>::Layer as Layer>::Service>>>::Service; impl Upgradable for Operation where @@ -250,17 +244,13 @@ where // The plugin takes this operation as input Pl: Plugin, - // The modified Layer applies correctly to `Upgrade` - Pl::Layer: Layer>, - - // The signature of the output is correct - >>::Service: - Service, Response = http::Response>, + // The modified Layer applies correctly to `Upgrade` + Pl::Layer: Layer>, // For `Route::new` for the resulting service - >>::Service: Service, Error = Infallible>, - UpgradedService: Clone + Send + 'static, - as Service>>::Future: Send + 'static, + UpgradedService: + Service, Response = http::Response, Error = Infallible> + Clone + Send + 'static, + as Service>>::Future: Send + 'static, { /// Takes the [`Operation`](Operation), applies [`Plugin`], then applies [`UpgradeLayer`] to /// the modified `S`, then finally applies the modified `L`. -- GitLab