Skip to content

Commit

Permalink
Incorporate feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed May 12, 2023
1 parent d2303a3 commit 49d10ae
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 245 deletions.
16 changes: 0 additions & 16 deletions codegen-client-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,6 @@ val allCodegenTests = "../codegen-core/common-test-models".let { commonModels ->
""".trimIndent(),
imports = listOf("$commonModels/naming-obstacle-course-structs.smithy"),
),
CodegenTest(
"crate#Config",
"naming_test_prelude_ops",
"""
, "codegen": { "renameErrors": false }
""".trimIndent(),
imports = listOf("$commonModels/naming-obstacle-course-prelude-ops.smithy"),
),
CodegenTest(
"crate#Config",
"naming_test_prelude_structs",
"""
, "codegen": { "renameErrors": false }
""".trimIndent(),
imports = listOf("$commonModels/naming-obstacle-course-prelude-structs.smithy"),
),
CodegenTest("aws.protocoltests.json#TestService", "endpoint-rules"),
CodegenTest("com.aws.example.rust#PokemonService", "pokemon-service-client", imports = listOf("$commonModels/pokemon.smithy", "$commonModels/pokemon-common.smithy")),
CodegenTest("com.aws.example.rust#PokemonService", "pokemon-service-awsjson-client", imports = listOf("$commonModels/pokemon-awsjson.smithy", "$commonModels/pokemon-common.smithy")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ data class InfallibleEnumType(
impl ::std::str::FromStr for ${context.enumName} {
type Err = ::std::convert::Infallible;
fn from_str(s: &str) -> #{Result}<Self, Self::Err> {
fn from_str(s: &str) -> #{Result}<Self, <Self as ::std::str::FromStr>::Err> {
#{Ok}(${context.enumName}::from(s))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy

import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
import software.amazon.smithy.rust.codegen.core.testutil.NamingObstacleCourseTestModels.rustPreludeEnumVariantsModel
import software.amazon.smithy.rust.codegen.core.testutil.NamingObstacleCourseTestModels.rustPreludeEnumsModel
import software.amazon.smithy.rust.codegen.core.testutil.NamingObstacleCourseTestModels.rustPreludeOperationsModel
import software.amazon.smithy.rust.codegen.core.testutil.NamingObstacleCourseTestModels.rustPreludeStructsModel

class NamingObstacleCourseTest {
@Test
fun `test Rust prelude operation names compile`() {
clientIntegrationTest(rustPreludeOperationsModel()) { _, _ -> }
}

@Test
fun `test Rust prelude structure names compile`() {
clientIntegrationTest(rustPreludeStructsModel()) { _, _ -> }
}

@Test
fun `test Rust prelude enum names compile`() {
clientIntegrationTest(rustPreludeEnumsModel()) { _, _ -> }
}

@Test
fun `test Rust prelude enum variant names compile`() {
clientIntegrationTest(rustPreludeEnumVariantsModel()) { _, _ -> }
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,14 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)
* The companion object contains commonly used RuntimeTypes
*/
companion object {
/** Scope that contains all Rust prelude types, but not macros or functions */
/**
* Scope that contains all Rust prelude types, but not macros or functions.
*
* Prelude docs: https://doc.rust-lang.org/std/prelude/index.html#prelude-contents
*/
val preludeScope by lazy {
arrayOf(
// Rust 1.0
"Copy" to std.resolve("marker::Copy"),
"Send" to Send,
"Sized" to std.resolve("marker::Sized"),
Expand Down Expand Up @@ -231,6 +236,11 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)
"String" to String,
"ToString" to std.resolve("string::ToString"),
"Vec" to Vec,

// 2021 Edition
"TryFrom" to std.resolve("convert::TryFrom"),
"TryInto" to std.resolve("convert::TryInto"),
"FromIterator" to std.resolve("iter::FromIterator"),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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.MaybeRenamed
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata
import software.amazon.smithy.rust.codegen.core.smithy.renamedFrom
Expand Down Expand Up @@ -208,14 +209,15 @@ open class EnumGenerator(
}
},
)
rust(
rustTemplate(
"""
impl AsRef<str> for ${context.enumName} {
impl #{AsRef}<str> for ${context.enumName} {
fn as_ref(&self) -> &str {
self.as_str()
}
}
""",
*preludeScope,
)
}

Expand All @@ -238,8 +240,7 @@ open class EnumGenerator(
}
}
""",
"From" to RuntimeType.From,
"AsRef" to RuntimeType.AsRef,
*preludeScope,
)
}

Expand Down
Loading

0 comments on commit 49d10ae

Please sign in to comment.