From a441612b7b8db6c7139e6bf7236b88ef4f65f253 Mon Sep 17 00:00:00 2001 From: Harry Barber Date: Tue, 11 Oct 2022 21:55:41 +0000 Subject: [PATCH] Add boxed method to service builder --- .../generators/ServerServiceGeneratorV2.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 d63ed4cd73..3f44b9d671 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 @@ -279,7 +279,7 @@ class ServerServiceGeneratorV2( rustTemplate( """ ##[derive(Clone)] - pub struct $serviceName { + pub struct $serviceName { router: #{SmithyHttpServer}::routers::RoutingService<#{Router}, #{Protocol}>, } @@ -321,6 +321,21 @@ class ServerServiceGeneratorV2( router: self.router.map(|s| s.layer(layer)) } } + + /// Applies [`Route::new`](#{SmithyHttpServer}::routing::Route::new) to all routes. + /// + /// This has the effect of erasing all types accumulated via [`layer`]. + pub fn boxed(self) -> $serviceName<#{SmithyHttpServer}::routing::Route> + where + S: #{Tower}::Service< + #{Http}::Request, + Response = #{Http}::Response<#{SmithyHttpServer}::body::BoxBody>, + Error = std::convert::Infallible>, + S: Clone + Send + 'static, + S::Future: Send + 'static, + { + self.layer(&#{Tower}::layer::layer_fn(#{SmithyHttpServer}::routing::Route::new)) + } } impl #{Tower}::Service<#{Http}::Request> for $serviceName