Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the new service builder #2021

Merged
merged 26 commits into from
Dec 1, 2022
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e6e7a2f
Document the new service builder
82marbag Nov 22, 2022
3dfc04b
Generate docs for current service
82marbag Nov 22, 2022
79dc931
Address comments
82marbag Nov 23, 2022
ddbedf1
Rename variable
82marbag Nov 23, 2022
630a914
Merge branch 'main' into new-service-builder-docs
82marbag Nov 23, 2022
f7a2393
Change handler names
82marbag Nov 23, 2022
7a13a5f
Update docs
82marbag Nov 24, 2022
28cfe35
Update docs
82marbag Nov 24, 2022
c6e321d
Update docs
Nov 24, 2022
bb75fde
Update docs
82marbag Nov 24, 2022
58292cc
Merge branch 'main' into new-service-builder-docs
82marbag Nov 24, 2022
2260908
Update dependencies
82marbag Nov 24, 2022
566d12a
Update docs
82marbag Nov 25, 2022
0a943c6
Update docs
82marbag Nov 25, 2022
f687d5d
Address comments
82marbag Nov 29, 2022
78cc474
Address comments
82marbag Nov 30, 2022
28f182f
Fix CI
82marbag Nov 30, 2022
9e3bf62
Fix CI
82marbag Nov 30, 2022
bc9e5bd
Fix CI
82marbag Nov 30, 2022
8faff7d
Fix CI
82marbag Nov 30, 2022
9ec3ad3
Address comments
82marbag Nov 30, 2022
f2f83df
Update codegen-server/src/main/kotlin/software/amazon/smithy/rust/cod…
82marbag Nov 30, 2022
90fca46
Update codegen-server/src/main/kotlin/software/amazon/smithy/rust/cod…
82marbag Nov 30, 2022
43b45dd
Update codegen-server/src/main/kotlin/software/amazon/smithy/rust/cod…
82marbag Nov 30, 2022
be9335b
Update codegen-server/src/main/kotlin/software/amazon/smithy/rust/cod…
82marbag Nov 30, 2022
9d63316
Merge branch 'main' into new-service-builder-docs
LukeMathWalker Dec 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.Errors
import software.amazon.smithy.rust.codegen.core.smithy.Inputs
import software.amazon.smithy.rust.codegen.core.smithy.Outputs
import software.amazon.smithy.rust.codegen.core.util.toPascalCase
import software.amazon.smithy.rust.codegen.core.util.toSnakeCase
import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency
Expand Down Expand Up @@ -469,6 +472,7 @@ class ServerServiceGeneratorV2(
}

fun render(writer: RustWriter) {
val crateName = codegenContext.moduleUseName()
val handlers: Writable = operations
.map { operation ->
DocHandlerGenerator(operation, "///", builderFieldNames[operation]!!, codegenContext).docSignature()
Expand All @@ -481,12 +485,17 @@ class ServerServiceGeneratorV2(

writer.rustTemplate(
"""
/// This module contains the implementation of $serviceName.
/// [`$serviceName`] is used to set your business logic to implement your [operations],
/// A fast and customizable Rust implementation of the $serviceName Smithy service.
///
/// This crate provides all types required to setup the [`$serviceName`] Service.
/// The [`$crateName::${Inputs.namespace}`], [`$crateName::${Outputs.namespace}`], and [`$crateName::${Errors.namespace}`] modules provide the types used in each operation.
82marbag marked this conversation as resolved.
Show resolved Hide resolved
///
/// The primary export is [`$serviceName`]: it is the
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
/// [`$builderName`] is used to set your business logic to implement your [operations],
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
/// customize your [operations]'s behaviors by applying middleware,
/// and run your server.
/// and build your service.
///
/// [`$serviceName`] contains the [operations] modeled in your Smithy service.
/// [`$builderName`] contains the [operations] modeled in your Smithy service.
/// You must set an implementation for all operations with the correct signature,
/// or your service will fail to be constructed at runtime and panic.
/// For each of the [operations] modeled in
Expand All @@ -495,8 +504,7 @@ class ServerServiceGeneratorV2(
/// operation's input as their first parameter, and returns the
/// operation's output. If your operation is fallible (i.e. it
/// contains the `errors` member in your Smithy model), the function
/// implementing the operation has to be fallible (i.e. return a
/// [`Result`]).
/// implementing the operation has to be fallible (i.e. return a [`Result`]).
/// The possible forms for your async functions are:
/// ```rust
/// async fn handler_fallible(input: Input, extensions: #{SmithyHttpServer}Extension<T>) -> Result<Output, Error>;
Expand All @@ -511,26 +519,26 @@ class ServerServiceGeneratorV2(
/// ```
/// For a full list of the possible extensions, see: [`#{SmithyHttpServer}::request`]. Any `T: Send + Sync + 'static` is also allowed.
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
///
/// To construct [`$serviceName`], you can build:
/// * [`$serviceName::builder_without_plugins()`] which returns a [`$builderName`] without any middleware applied.
/// To construct [`$serviceName`], you can use:
/// * [`$serviceName::builder_without_plugins()`] which returns a [`$builderName`] without any service-wide middleware applied.
/// * [`$serviceName::builder_with_plugins(plugins)`] which returns a [`$builderName`] that applies `plugins` to all your operations.
///
/// To know more about plugins, see: [`#{SmithyHttpServer}::plugin`].
82marbag marked this conversation as resolved.
Show resolved Hide resolved
///
/// When you have set all your operations, you can convert [`$serviceName`] into a [Service] calling:
/// When you have set all your operations, you can convert [`$serviceName`] into a tower [Service] calling:
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
/// * [`$serviceName::into_make_service`] that converts $serviceName into a type that implements [`tower::make::MakeService`], a _service factory_.
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
/// * [`$serviceName::into_make_service_with_connect_info`] that converts $serviceName into [`tower::make::MakeService`]
/// with [`ConnectInfo`](#{SmithyHttpServer}::request::connect_info::ConnectInfo).
/// You can write your implementations to be passed in the connection information, populated by the [Hyper server], as an [`#{SmithyHttpServer}Extension`].
///
/// You can feed this value to a [Hyper server], and the
/// You can feed this [Service] to a [Hyper server], and the
/// server will instantiate and [`serve`] your service.
///
/// Here's a full example to get you started:
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
///
/// ```rust
/// use std::net::SocketAddr;
/// use ${codegenContext.moduleUseName()}::$serviceName;
/// use $crateName::$serviceName;
///
/// ##[tokio::main]
/// pub async fn main() {
Expand Down