Unverified Commit 20ad8886 authored by david-perez's avatar david-perez Committed by GitHub
Browse files

AWS JSON 1.x server request specs can be `&'static str`s (#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._
parent 1588945c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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()
+2 −2
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
[package]
name = "aws-smithy-http-server"
version = "0.63.0"
version = "0.63.1"
authors = ["Smithy Rust Server <smithy-rs-server@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
+4 −8
Original line number Diff line number Diff line
@@ -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> {
@@ -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(),
        }
@@ -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"));