diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index a23ab7455c..918e5140bc 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -162,3 +162,9 @@ filter_by_operation_id(plugin, |id| id.absolute() != "namespace#name"); author = "82marbag" references = ["smithy-rs#2678"] meta = { "breaking" = true, "tada" = false, "bug" = false } + +[[smithy-rs]] +message = "The occurrences of `Arc` have now been replaced with `SharedEndpointResolver` in public APIs." +references = ["smithy-rs#2758"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" } +author = "ysaito1001" diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt index ac2e8928e0..695110e590 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt @@ -45,6 +45,7 @@ class TimestreamDecorator : ClientCodegenDecorator { }, ) } + override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { val endpointDiscovery = InlineAwsDependency.forRustFile( "endpoint_discovery", @@ -87,7 +88,7 @@ class TimestreamDecorator : ClientCodegenDecorator { time ) .await?; - new_conf.endpoint_resolver = ::std::sync::Arc::new(resolver); + new_conf.endpoint_resolver = #{SharedEndpointResolver}::new(resolver); Ok((Self::from_conf(new_conf), reloader)) } } @@ -96,6 +97,8 @@ class TimestreamDecorator : ClientCodegenDecorator { "endpoint_discovery" to endpointDiscovery.toType(), "SystemTime" to RuntimeType.std.resolve("time::SystemTime"), "Duration" to RuntimeType.std.resolve("time::Duration"), + "SharedEndpointResolver" to RuntimeType.smithyHttp(codegenContext.runtimeConfig) + .resolve("endpoint::SharedEndpointResolver"), "SystemTimeSource" to RuntimeType.smithyAsync(codegenContext.runtimeConfig) .resolve("time::SystemTimeSource"), *Types(codegenContext.runtimeConfig).toArray(), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointConfigCustomization.kt index 2d742bbbec..6d74f1a7dc 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointConfigCustomization.kt @@ -13,6 +13,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.Writable 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.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope /** * Customization which injects an Endpoints 2.0 Endpoint Resolver into the service config struct @@ -28,14 +29,17 @@ internal class EndpointConfigCustomization( override fun section(section: ServiceConfig): Writable { return writable { + val sharedEndpointResolver = "#{SharedEndpointResolver}<#{Params}>" val resolverTrait = "#{SmithyResolver}<#{Params}>" val codegenScope = arrayOf( + *preludeScope, + "SharedEndpointResolver" to types.sharedEndpointResolver, "SmithyResolver" to types.resolveEndpoint, "Params" to typesGenerator.paramsStruct(), ) when (section) { is ServiceConfig.ConfigStruct -> rustTemplate( - "pub (crate) endpoint_resolver: std::sync::Arc,", + "pub (crate) endpoint_resolver: $sharedEndpointResolver,", *codegenScope, ) @@ -43,7 +47,7 @@ internal class EndpointConfigCustomization( rustTemplate( """ /// Returns the endpoint resolver. - pub fn endpoint_resolver(&self) -> std::sync::Arc { + pub fn endpoint_resolver(&self) -> $sharedEndpointResolver { self.endpoint_resolver.clone() } """, @@ -52,7 +56,7 @@ internal class EndpointConfigCustomization( is ServiceConfig.BuilderStruct -> rustTemplate( - "endpoint_resolver: Option>,", + "endpoint_resolver: #{Option}<$sharedEndpointResolver>,", *codegenScope, ) @@ -99,7 +103,7 @@ internal class EndpointConfigCustomization( /// Sets the endpoint resolver to use when making requests. $defaultResolverDocs pub fn endpoint_resolver(mut self, endpoint_resolver: impl $resolverTrait + 'static) -> Self { - self.endpoint_resolver = Some(std::sync::Arc::new(endpoint_resolver) as _); + self.endpoint_resolver = #{Some}(#{SharedEndpointResolver}::new(endpoint_resolver)); self } @@ -107,7 +111,7 @@ internal class EndpointConfigCustomization( /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `$moduleUseName`. - pub fn set_endpoint_resolver(&mut self, endpoint_resolver: Option>) -> &mut Self { + pub fn set_endpoint_resolver(&mut self, endpoint_resolver: #{Option}<$sharedEndpointResolver>) -> &mut Self { self.endpoint_resolver = endpoint_resolver; self } @@ -122,7 +126,7 @@ internal class EndpointConfigCustomization( rustTemplate( """ endpoint_resolver: self.endpoint_resolver.unwrap_or_else(|| - std::sync::Arc::new(#{DefaultResolver}::new()) + #{SharedEndpointResolver}::new(#{DefaultResolver}::new()) ), """, *codegenScope, @@ -150,8 +154,9 @@ internal class EndpointConfigCustomization( // always fail. In the future, this will be changed to an `expect()` rustTemplate( """ - endpoint_resolver: self.endpoint_resolver.unwrap_or_else(||std::sync::Arc::new(#{FailingResolver})), + endpoint_resolver: self.endpoint_resolver.unwrap_or_else(||#{SharedEndpointResolver}::new(#{FailingResolver})), """, + *codegenScope, "FailingResolver" to alwaysFailsResolver, ) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointsDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointsDecorator.kt index c6384a3861..c2cf1c9fd3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointsDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointsDecorator.kt @@ -169,12 +169,14 @@ class EndpointsDecorator : ClientCodegenDecorator { val codegenScope = arrayOf( *RuntimeType.preludeScope, "Params" to typesGenerator.paramsStruct(), + "ResolveEndpoint" to types.resolveEndpoint, "ResolveEndpointError" to types.resolveEndpointError, ) return when (section) { is OperationSection.MutateInput -> writable { rustTemplate( """ + use #{ResolveEndpoint}; let params_result = #{Params}::builder()#{builderFields:W}.build() .map_err(|err| #{ResolveEndpointError}::from_source("could not construct endpoint parameters", err)); let (endpoint_result, params) = match params_result { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt index df909e9452..bed14f40ae 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt @@ -48,6 +48,7 @@ class Types(runtimeConfig: RuntimeConfig) { private val smithyTypesEndpointModule = RuntimeType.smithyTypes(runtimeConfig).resolve("endpoint") val smithyHttpEndpointModule = RuntimeType.smithyHttp(runtimeConfig).resolve("endpoint") val resolveEndpoint = smithyHttpEndpointModule.resolve("ResolveEndpoint") + val sharedEndpointResolver = smithyHttpEndpointModule.resolve("SharedEndpointResolver") val smithyEndpoint = smithyTypesEndpointModule.resolve("Endpoint") val resolveEndpointError = smithyHttpEndpointModule.resolve("ResolveEndpointError") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceRuntimePluginGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceRuntimePluginGenerator.kt index e495aeae2c..0d6b924584 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceRuntimePluginGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceRuntimePluginGenerator.kt @@ -97,7 +97,6 @@ class ServiceRuntimePluginGenerator( "Params" to endpointTypesGenerator.paramsStruct(), "ResolveEndpoint" to http.resolve("endpoint::ResolveEndpoint"), "RuntimePlugin" to runtimeApi.resolve("client::runtime_plugin::RuntimePlugin"), - "SharedEndpointResolver" to http.resolve("endpoint::SharedEndpointResolver"), "StaticAuthOptionResolver" to runtimeApi.resolve("client::auth::option_resolver::StaticAuthOptionResolver"), "default_connector" to client.resolve("conns::default_connector"), "require_connector" to client.resolve("conns::require_connector"), @@ -134,7 +133,7 @@ class ServiceRuntimePluginGenerator( cfg.set_auth_option_resolver(#{StaticAuthOptionResolver}::new(#{Vec}::new())); let endpoint_resolver = #{DefaultEndpointResolver}::<#{Params}>::new( - #{SharedEndpointResolver}::from(self.handle.conf.endpoint_resolver())); + self.handle.conf.endpoint_resolver()); cfg.set_endpoint_resolver(endpoint_resolver); // TODO(enableNewSmithyRuntime): Use the `store_append` method of ConfigBag to insert classifiers