Loading aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ internal class EndpointConfigCustomizationTest { @Test fun `write an endpoint into the config`() { val project = stubConfigProject(EndpointConfigCustomization(TestRuntimeConfig, model.lookup("test#TestService"))) project.useFileWriter("src/lib.rs", "crate") { project.lib { it.addDependency(awsTypes(TestRuntimeConfig)) it.addDependency(CargoDependency.Http) it.unitTest( Loading aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ internal class SigV4SigningCustomizationTest { @Test fun `generates a valid config`() { val project = stubConfigProject(SigV4SigningConfig(SigV4Trait.builder().name("test-service").build())) project.useFileWriter("src/lib.rs", "crate") { project.lib { it.unitTest( """ let conf = crate::config::Config::builder().build(); Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt +6 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,8 @@ class InlineDependency( fun CargoDependency.asType(): RuntimeType = RuntimeType(null, dependency = this, namespace = this.name.replace("-", "_")) data class Feature(val name: String, val default: Boolean, val deps: List<String>) /** * A dependency on an internal or external Cargo Crate */ Loading @@ -113,6 +115,7 @@ data class CargoDependency( override val name: String, private val location: DependencyLocation, val scope: DependencyScope = DependencyScope.Compile, val optional: Boolean = false, private val features: List<String> = listOf() ) : RustDependency(name) { Loading @@ -137,6 +140,9 @@ data class CargoDependency( attribs["features"] = this } } if (optional) { attribs["optional"] = true } return attribs } Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustModule.kt +3 −0 Original line number Diff line number Diff line Loading @@ -21,5 +21,8 @@ data class RustModule(val name: String, val rustMetadata: RustMetadata) { }*/ return RustModule(name, RustMetadata(public = public)) } val Config = default("config", public = true) val Error = default("error", public = true) } } codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustTypes.kt +30 −21 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ package software.amazon.smithy.rust.codegen.rustlang import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.util.dq /** * A hierarchy of types handled by Smithy codegen Loading Loading @@ -149,14 +150,15 @@ inline fun <reified T : RustType.Container> RustType.stripOuter(): RustType { * Meta information about a Rust construction (field, struct, or enum) */ data class RustMetadata( val derives: Derives = Derives.Empty, val derives: Attribute.Derives = Attribute.Derives.Empty, val additionalAttributes: List<Attribute> = listOf(), val public: Boolean ) { fun withDerives(vararg newDerive: RuntimeType): RustMetadata = this.copy(derives = derives.copy(derives = derives.derives + newDerive)) fun attributes(): List<Attribute> = additionalAttributes + derives private fun attributes(): List<Attribute> = additionalAttributes + derives fun renderAttributes(writer: RustWriter): RustMetadata { attributes().forEach { it.render(writer) Loading Loading @@ -201,7 +203,6 @@ sealed class Attribute { val NonExhaustive = Custom("non_exhaustive") val AllowUnused = Custom("allow(dead_code)") } } data class Derives(val derives: Set<RuntimeType>) : Attribute() { override fun render(writer: RustWriter) { Loading @@ -220,14 +221,22 @@ data class Derives(val derives: Set<RuntimeType>) : Attribute() { } } data class Custom(val annot: String, val symbols: List<RuntimeType> = listOf()) : Attribute() { data class Custom(val annotation: String, val symbols: List<RuntimeType> = listOf()) : Attribute() { override fun render(writer: RustWriter) { writer.raw("#[") writer.writeInline(annot) writer.write("]") writer.raw("#[$annotation]") symbols.forEach { writer.addDependency(it.dependency) } } } data class Cfg(val cond: String) : Attribute() { override fun render(writer: RustWriter) { writer.raw("#[cfg($cond)]") } companion object { fun feature(feature: String) = Cfg("feature = ${feature.dq()}") } } } Loading
aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ internal class EndpointConfigCustomizationTest { @Test fun `write an endpoint into the config`() { val project = stubConfigProject(EndpointConfigCustomization(TestRuntimeConfig, model.lookup("test#TestService"))) project.useFileWriter("src/lib.rs", "crate") { project.lib { it.addDependency(awsTypes(TestRuntimeConfig)) it.addDependency(CargoDependency.Http) it.unitTest( Loading
aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ internal class SigV4SigningCustomizationTest { @Test fun `generates a valid config`() { val project = stubConfigProject(SigV4SigningConfig(SigV4Trait.builder().name("test-service").build())) project.useFileWriter("src/lib.rs", "crate") { project.lib { it.unitTest( """ let conf = crate::config::Config::builder().build(); Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt +6 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,8 @@ class InlineDependency( fun CargoDependency.asType(): RuntimeType = RuntimeType(null, dependency = this, namespace = this.name.replace("-", "_")) data class Feature(val name: String, val default: Boolean, val deps: List<String>) /** * A dependency on an internal or external Cargo Crate */ Loading @@ -113,6 +115,7 @@ data class CargoDependency( override val name: String, private val location: DependencyLocation, val scope: DependencyScope = DependencyScope.Compile, val optional: Boolean = false, private val features: List<String> = listOf() ) : RustDependency(name) { Loading @@ -137,6 +140,9 @@ data class CargoDependency( attribs["features"] = this } } if (optional) { attribs["optional"] = true } return attribs } Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustModule.kt +3 −0 Original line number Diff line number Diff line Loading @@ -21,5 +21,8 @@ data class RustModule(val name: String, val rustMetadata: RustMetadata) { }*/ return RustModule(name, RustMetadata(public = public)) } val Config = default("config", public = true) val Error = default("error", public = true) } }
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustTypes.kt +30 −21 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ package software.amazon.smithy.rust.codegen.rustlang import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.util.dq /** * A hierarchy of types handled by Smithy codegen Loading Loading @@ -149,14 +150,15 @@ inline fun <reified T : RustType.Container> RustType.stripOuter(): RustType { * Meta information about a Rust construction (field, struct, or enum) */ data class RustMetadata( val derives: Derives = Derives.Empty, val derives: Attribute.Derives = Attribute.Derives.Empty, val additionalAttributes: List<Attribute> = listOf(), val public: Boolean ) { fun withDerives(vararg newDerive: RuntimeType): RustMetadata = this.copy(derives = derives.copy(derives = derives.derives + newDerive)) fun attributes(): List<Attribute> = additionalAttributes + derives private fun attributes(): List<Attribute> = additionalAttributes + derives fun renderAttributes(writer: RustWriter): RustMetadata { attributes().forEach { it.render(writer) Loading Loading @@ -201,7 +203,6 @@ sealed class Attribute { val NonExhaustive = Custom("non_exhaustive") val AllowUnused = Custom("allow(dead_code)") } } data class Derives(val derives: Set<RuntimeType>) : Attribute() { override fun render(writer: RustWriter) { Loading @@ -220,14 +221,22 @@ data class Derives(val derives: Set<RuntimeType>) : Attribute() { } } data class Custom(val annot: String, val symbols: List<RuntimeType> = listOf()) : Attribute() { data class Custom(val annotation: String, val symbols: List<RuntimeType> = listOf()) : Attribute() { override fun render(writer: RustWriter) { writer.raw("#[") writer.writeInline(annot) writer.write("]") writer.raw("#[$annotation]") symbols.forEach { writer.addDependency(it.dependency) } } } data class Cfg(val cond: String) : Attribute() { override fun render(writer: RustWriter) { writer.raw("#[cfg($cond)]") } companion object { fun feature(feature: String) = Cfg("feature = ${feature.dq()}") } } }