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