Skip to content

Commit 20ad888

Browse files
authored
AWS JSON 1.x server request specs can be &'static strs (#3741)
This is technically a breaking change because we stop implementing `FromIterator<(String, S)>`. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 1588945 commit 20ad888

File tree

4 files changed

+10
-11
lines changed
  • codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy
  • codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol
  • rust-runtime/aws-smithy-http-server

4 files changed

+10
-11
lines changed

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)
272272
val U64 = std.resolve("primitive::u64")
273273
val Vec = std.resolve("vec::Vec")
274274

275+
// primitive types
276+
val StaticStr = RuntimeType("&'static str")
277+
275278
// external cargo dependency types
276279
val Bytes = CargoDependency.Bytes.toType().resolve("Bytes")
277280
val Http = CargoDependency.Http.toType()

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ class ServerAwsJsonProtocol(
163163
serviceName: String,
164164
requestSpecModule: RuntimeType,
165165
) = writable {
166-
rust("""String::from("$serviceName.$operationName")""")
166+
rust(""""$serviceName.$operationName"""")
167167
}
168168

169-
override fun serverRouterRequestSpecType(requestSpecModule: RuntimeType): RuntimeType = RuntimeType.String
169+
override fun serverRouterRequestSpecType(requestSpecModule: RuntimeType): RuntimeType = RuntimeType.StaticStr
170170

171171
override fun serverRouterRuntimeConstructor() =
172172
when (version) {

rust-runtime/aws-smithy-http-server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aws-smithy-http-server"
3-
version = "0.63.0"
3+
version = "0.63.1"
44
authors = ["Smithy Rust Server <smithy-rs-server@amazon.com>"]
55
edition = "2021"
66
license = "Apache-2.0"

rust-runtime/aws-smithy-http-server/src/protocol/aws_json/router.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const ROUTE_CUTOFF: usize = 15;
4747
/// [AWS JSON 1.1]: https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html
4848
#[derive(Debug, Clone)]
4949
pub struct AwsJsonRouter<S> {
50-
routes: TinyMap<String, S, ROUTE_CUTOFF>,
50+
routes: TinyMap<&'static str, S, ROUTE_CUTOFF>,
5151
}
5252

5353
impl<S> AwsJsonRouter<S> {
@@ -106,9 +106,9 @@ where
106106
}
107107
}
108108

109-
impl<S> FromIterator<(String, S)> for AwsJsonRouter<S> {
109+
impl<S> FromIterator<(&'static str, S)> for AwsJsonRouter<S> {
110110
#[inline]
111-
fn from_iter<T: IntoIterator<Item = (String, S)>>(iter: T) -> Self {
111+
fn from_iter<T: IntoIterator<Item = (&'static str, S)>>(iter: T) -> Self {
112112
Self {
113113
routes: iter.into_iter().collect(),
114114
}
@@ -126,11 +126,7 @@ mod tests {
126126
#[tokio::test]
127127
async fn simple_routing() {
128128
let routes = vec![("Service.Operation")];
129-
let router: AwsJsonRouter<_> = routes
130-
.clone()
131-
.into_iter()
132-
.map(|operation| (operation.to_string(), ()))
133-
.collect();
129+
let router: AwsJsonRouter<_> = routes.clone().into_iter().map(|operation| (operation, ())).collect();
134130

135131
let mut headers = HeaderMap::new();
136132
headers.insert("x-amz-target", HeaderValue::from_static("Service.Operation"));

0 commit comments

Comments
 (0)