Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/CargoDependency.kt +2 −1 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ class InlineDependency( ): InlineDependency { // The inline crate is loaded as a dependency on the runtime classpath val rustFile = this::class.java.getResource("/inlineable/src/$filename") check(rustFile != null) check(rustFile != null) { "Rust file $filename was missing from the resource bundle!" } return InlineDependency(name, module, additionalDepencies.toList()) { writer -> writer.raw(rustFile.readText()) } Loading @@ -86,6 +86,7 @@ class InlineDependency( fun docJson() = forRustFile("doc_json", "doc_json", "doc_json.rs", CargoDependency.Serde) fun instantEpoch() = forRustFile("instant_epoch", "instant_epoch", "instant_epoch.rs", CargoDependency.Serde) fun instantHttpDate() = forRustFile("instant_httpdate", "instant_httpdate", "instant_httpdate.rs", CargoDependency.Serde) fun instant8601() = forRustFile("instant_8601", "instant_8601", "instant_iso8601.rs", CargoDependency.Serde) // Stub config implementation as a placeholder before one can be generated dynamically fun config() = forRustFile("config", "config", "config.rs", CargoDependency.Rand) Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt +1 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,7 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n val InstantEpoch = RuntimeType("instant_epoch", InlineDependency.instantEpoch(), "crate") val InstantHttpDate = RuntimeType("instant_httpdate", InlineDependency.instantHttpDate(), "crate") val Instant8601 = RuntimeType("instant_8601", InlineDependency.instant8601(), "crate") val Config = RuntimeType("config", InlineDependency.config(), "crate") fun forInlineFun(name: String, module: String, func: (RustWriter) -> Unit) = RuntimeType( Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolTestGenerator.kt +0 −4 Original line number Diff line number Diff line Loading @@ -364,10 +364,6 @@ class HttpProtocolTestGenerator( Action.Request ), // Timestamp parsing: https://github.com/awslabs/smithy-rs/issues/80 // FailingTest(AwsJson11, "parses_httpdate_timestamps", Action.Response), FailingTest(AwsJson11, "parses_iso8601_timestamps", Action.Response), // Document deserialization: FailingTest(AwsJson11, "PutAndGetInlineDocumentsInput", Action.Response) ) Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/JsonSerializerSymbolProvider.kt +9 −0 Original line number Diff line number Diff line Loading @@ -242,6 +242,15 @@ class SerializerBuilder( """, RuntimeType.InstantHttpDate ) }, "stdoptionoptioninstant_date_time_deser" to { writer -> writer.write("use #T;", RuntimeType.Deserialize) writer.rust( """ Ok(Option::<#T::InstantIso8601>::deserialize(_deser)?.map(|i|i.0)) """, RuntimeType.Instant8601 ) } ) Loading rust-runtime/inlineable/src/config.rs +14 −8 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0. */ // TODO: Generate the config dynamically based on the requirements of the service use std::sync::Mutex; Loading Loading @@ -40,8 +39,10 @@ fn default_provider() -> impl ProvideIdempotencyToken { Mutex::new(rand::thread_rng()) } impl<T> ProvideIdempotencyToken for Mutex<T> where T: rand::Rng { impl<T> ProvideIdempotencyToken for Mutex<T> where T: rand::Rng, { fn token(&self) -> String { let input: u128 = self.lock().unwrap().gen(); v4(input) Loading @@ -56,7 +57,7 @@ impl ProvideIdempotencyToken for &'static str { pub struct Config { #[allow(dead_code)] pub(crate) token_provider: Box<dyn ProvideIdempotencyToken> pub(crate) token_provider: Box<dyn ProvideIdempotencyToken>, } impl Config { Loading @@ -71,7 +72,7 @@ impl Config { #[derive(Default)] pub struct ConfigBuilder { #[allow(dead_code)] token_provider: Option<Box<dyn ProvideIdempotencyToken>> token_provider: Option<Box<dyn ProvideIdempotencyToken>>, } impl ConfigBuilder { Loading @@ -79,14 +80,19 @@ impl ConfigBuilder { Self::default() } pub fn token_provider(mut self, token_provider: impl ProvideIdempotencyToken + 'static) -> Self { pub fn token_provider( mut self, token_provider: impl ProvideIdempotencyToken + 'static, ) -> Self { self.token_provider = Some(Box::new(token_provider)); self } pub fn build(self) -> Config { Config { token_provider: self.token_provider.unwrap_or_else(|| Box::new(default_provider())) token_provider: self .token_provider .unwrap_or_else(|| Box::new(default_provider())), } } } Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/CargoDependency.kt +2 −1 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ class InlineDependency( ): InlineDependency { // The inline crate is loaded as a dependency on the runtime classpath val rustFile = this::class.java.getResource("/inlineable/src/$filename") check(rustFile != null) check(rustFile != null) { "Rust file $filename was missing from the resource bundle!" } return InlineDependency(name, module, additionalDepencies.toList()) { writer -> writer.raw(rustFile.readText()) } Loading @@ -86,6 +86,7 @@ class InlineDependency( fun docJson() = forRustFile("doc_json", "doc_json", "doc_json.rs", CargoDependency.Serde) fun instantEpoch() = forRustFile("instant_epoch", "instant_epoch", "instant_epoch.rs", CargoDependency.Serde) fun instantHttpDate() = forRustFile("instant_httpdate", "instant_httpdate", "instant_httpdate.rs", CargoDependency.Serde) fun instant8601() = forRustFile("instant_8601", "instant_8601", "instant_iso8601.rs", CargoDependency.Serde) // Stub config implementation as a placeholder before one can be generated dynamically fun config() = forRustFile("config", "config", "config.rs", CargoDependency.Rand) Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt +1 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,7 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n val InstantEpoch = RuntimeType("instant_epoch", InlineDependency.instantEpoch(), "crate") val InstantHttpDate = RuntimeType("instant_httpdate", InlineDependency.instantHttpDate(), "crate") val Instant8601 = RuntimeType("instant_8601", InlineDependency.instant8601(), "crate") val Config = RuntimeType("config", InlineDependency.config(), "crate") fun forInlineFun(name: String, module: String, func: (RustWriter) -> Unit) = RuntimeType( Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolTestGenerator.kt +0 −4 Original line number Diff line number Diff line Loading @@ -364,10 +364,6 @@ class HttpProtocolTestGenerator( Action.Request ), // Timestamp parsing: https://github.com/awslabs/smithy-rs/issues/80 // FailingTest(AwsJson11, "parses_httpdate_timestamps", Action.Response), FailingTest(AwsJson11, "parses_iso8601_timestamps", Action.Response), // Document deserialization: FailingTest(AwsJson11, "PutAndGetInlineDocumentsInput", Action.Response) ) Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/JsonSerializerSymbolProvider.kt +9 −0 Original line number Diff line number Diff line Loading @@ -242,6 +242,15 @@ class SerializerBuilder( """, RuntimeType.InstantHttpDate ) }, "stdoptionoptioninstant_date_time_deser" to { writer -> writer.write("use #T;", RuntimeType.Deserialize) writer.rust( """ Ok(Option::<#T::InstantIso8601>::deserialize(_deser)?.map(|i|i.0)) """, RuntimeType.Instant8601 ) } ) Loading
rust-runtime/inlineable/src/config.rs +14 −8 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0. */ // TODO: Generate the config dynamically based on the requirements of the service use std::sync::Mutex; Loading Loading @@ -40,8 +39,10 @@ fn default_provider() -> impl ProvideIdempotencyToken { Mutex::new(rand::thread_rng()) } impl<T> ProvideIdempotencyToken for Mutex<T> where T: rand::Rng { impl<T> ProvideIdempotencyToken for Mutex<T> where T: rand::Rng, { fn token(&self) -> String { let input: u128 = self.lock().unwrap().gen(); v4(input) Loading @@ -56,7 +57,7 @@ impl ProvideIdempotencyToken for &'static str { pub struct Config { #[allow(dead_code)] pub(crate) token_provider: Box<dyn ProvideIdempotencyToken> pub(crate) token_provider: Box<dyn ProvideIdempotencyToken>, } impl Config { Loading @@ -71,7 +72,7 @@ impl Config { #[derive(Default)] pub struct ConfigBuilder { #[allow(dead_code)] token_provider: Option<Box<dyn ProvideIdempotencyToken>> token_provider: Option<Box<dyn ProvideIdempotencyToken>>, } impl ConfigBuilder { Loading @@ -79,14 +80,19 @@ impl ConfigBuilder { Self::default() } pub fn token_provider(mut self, token_provider: impl ProvideIdempotencyToken + 'static) -> Self { pub fn token_provider( mut self, token_provider: impl ProvideIdempotencyToken + 'static, ) -> Self { self.token_provider = Some(Box::new(token_provider)); self } pub fn build(self) -> Config { Config { token_provider: self.token_provider.unwrap_or_else(|| Box::new(default_provider())) token_provider: self .token_provider .unwrap_or_else(|| Box::new(default_provider())), } } }