Repository: smithy-lang/smithy-rs (language: rust)

Issue:
Regression in 0.57 where default generic for service struct was removed
Prior to 0.57, one could build and return a service from a function like this:

```rust
pub fn build_service() -> PokemonService {
    let service = PokemonService::builder_without_plugins()
        .operation(operation_handler)
        .build()
        .expect("unable to build service");

    service.boxed()
}
```

This is because we had a default generic on the service struct. But since #3095, this no longer compiles, because we accidentally removed that default generic:

![image](https://github.com/smithy-lang/smithy-rs/assets/6341745/8261f2bf-b554-4d4f-a28f-78f051898466)

So even in the most common use case where the user doesn't want to be generic over the body type and was satisfied with `aws_smithy_http_server::body::Body`, they now need to write this function as:

```rust
pub fn build_service() -> PokemonService<
    aws_smithy_http_server::routing::RoutingService<
      aws_smithy_http_server::protocol::rest::router::RestRouter<
        aws_smithy_http_server::routing::Route<aws_smithy_http_server::body::Body>,
      >,
      aws_smithy_http_server::protocol::rest_json_1::RestJson1,
    >,
> {
    let service = PokemonService::builder_without_plugins()
        .operation(operation_handler)
        .build()
        .expect("unable to build service");

    service.boxed()
}
```

This is a regression we didn't catch because we don't have any tests in our suite that initialize the service within a function. We should keep providing a default for the `S` generic for the most common use case.



Discussion / hints:

Fix patch:
diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt
index 79b087ee14..8eaec006a7 100644
--- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt
+++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt
@@ -488,7 +488,16 @@ class ServerServiceGenerator(
             ///
             /// See the [root](crate) documentation for more information.
             ##[derive(Clone)]
-            pub struct $serviceName<S> {
+            pub struct $serviceName<
+                S = #{SmithyHttpServer}::routing::RoutingService<
+                    #{Router}<
+                        #{SmithyHttpServer}::routing::Route<
+                            #{SmithyHttpServer}::body::BoxBody
+                        >,
+                    >,
+                    #{Protocol},
+                >
+            > {
                 // This is the router wrapped by layers.
                 svc: S,
             }


Test patch:
diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorTest.kt
new file mode 100644
index 0000000000..6e110f9641
--- /dev/null
+++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorTest.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package software.amazon.smithy.rust.codegen.server.smithy.generators
+
+import org.junit.jupiter.api.Test
+import software.amazon.smithy.rust.codegen.core.rustlang.rust
+import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
+import software.amazon.smithy.rust.codegen.core.testutil.testModule
+import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverIntegrationTest
+import java.io.File
+
+internal class ServerServiceGeneratorTest {
+    /**
+     * See <https://github.com/smithy-lang/smithy-rs/issues/3177>.
+     */
+    @Test
+    fun `one should be able to return a built service from a function`() {
+        val model = File("../codegen-core/common-test-models/simple.smithy").readText().asSmithyModel()
+
+        serverIntegrationTest(model) { _, rustCrate ->
+            rustCrate.testModule {
+                // No actual tests: we just want to check that this compiles.
+                rust(
+                    """
+                    fn _build_service() -> crate::SimpleService {
+                        let config = crate::SimpleServiceConfig::builder().build();
+                        let service = crate::SimpleService::builder(config).build_unchecked();
+
+                        service.boxed()
+                    }
+                    """,
+                )
+            }
+        }
+    }
+}