Skip to content

Commit

Permalink
Add boxed method to service builder (#1840)
Browse files Browse the repository at this point in the history
  • Loading branch information
hlbarber authored Oct 25, 2022
1 parent 425d91b commit 6b3e311
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class ServerServiceGeneratorV2(
rustTemplate(
"""
##[derive(Clone)]
pub struct $serviceName<S> {
pub struct $serviceName<S = #{SmithyHttpServer}::routing::Route> {
router: #{SmithyHttpServer}::routers::RoutingService<#{Router}<S>, #{Protocol}>,
}
Expand Down Expand Up @@ -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<B>(self) -> $serviceName<#{SmithyHttpServer}::routing::Route<B>>
where
S: #{Tower}::Service<
#{Http}::Request<B>,
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<B, RespB, S> #{Tower}::Service<#{Http}::Request<B>> for $serviceName<S>
Expand Down

0 comments on commit 6b3e311

Please sign in to comment.