Skip to content

Commit

Permalink
AWS JSON 1.x server request specs can be &'static strs (#3741)
Browse files Browse the repository at this point in the history
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._
  • Loading branch information
david-perez authored Jul 8, 2024
1 parent 1588945 commit 20ad888
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)
val U64 = std.resolve("primitive::u64")
val Vec = std.resolve("vec::Vec")

// primitive types
val StaticStr = RuntimeType("&'static str")

// external cargo dependency types
val Bytes = CargoDependency.Bytes.toType().resolve("Bytes")
val Http = CargoDependency.Http.toType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ class ServerAwsJsonProtocol(
serviceName: String,
requestSpecModule: RuntimeType,
) = writable {
rust("""String::from("$serviceName.$operationName")""")
rust(""""$serviceName.$operationName"""")
}

override fun serverRouterRequestSpecType(requestSpecModule: RuntimeType): RuntimeType = RuntimeType.String
override fun serverRouterRequestSpecType(requestSpecModule: RuntimeType): RuntimeType = RuntimeType.StaticStr

override fun serverRouterRuntimeConstructor() =
when (version) {
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-http-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-http-server"
version = "0.63.0"
version = "0.63.1"
authors = ["Smithy Rust Server <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const ROUTE_CUTOFF: usize = 15;
/// [AWS JSON 1.1]: https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html
#[derive(Debug, Clone)]
pub struct AwsJsonRouter<S> {
routes: TinyMap<String, S, ROUTE_CUTOFF>,
routes: TinyMap<&'static str, S, ROUTE_CUTOFF>,
}

impl<S> AwsJsonRouter<S> {
Expand Down Expand Up @@ -106,9 +106,9 @@ where
}
}

impl<S> FromIterator<(String, S)> for AwsJsonRouter<S> {
impl<S> FromIterator<(&'static str, S)> for AwsJsonRouter<S> {
#[inline]
fn from_iter<T: IntoIterator<Item = (String, S)>>(iter: T) -> Self {
fn from_iter<T: IntoIterator<Item = (&'static str, S)>>(iter: T) -> Self {
Self {
routes: iter.into_iter().collect(),
}
Expand All @@ -126,11 +126,7 @@ mod tests {
#[tokio::test]
async fn simple_routing() {
let routes = vec![("Service.Operation")];
let router: AwsJsonRouter<_> = routes
.clone()
.into_iter()
.map(|operation| (operation.to_string(), ()))
.collect();
let router: AwsJsonRouter<_> = routes.clone().into_iter().map(|operation| (operation, ())).collect();

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

0 comments on commit 20ad888

Please sign in to comment.