From b9601f83c3700f824e2143c230f36d6ac7dd5697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Varl=C4=B1?= Date: Tue, 10 Jan 2023 12:53:45 +0000 Subject: [PATCH] Allow Python specific `Document` type to be used in serialization and deserialization --- .../src/types.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rust-runtime/aws-smithy-http-server-python/src/types.rs b/rust-runtime/aws-smithy-http-server-python/src/types.rs index 2cbf59ec320..9df4293dc92 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/types.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/types.rs @@ -8,6 +8,7 @@ use std::{ collections::HashMap, future::Future, + ops::Deref, pin::Pin, sync::Arc, task::{Context, Poll}, @@ -493,6 +494,24 @@ impl FromPyObject<'_> for Document { } } +// TODO(PythonSerialization): Get rid of this hack. +// `JsonValueWriter::document` expects `&aws_smithy_types::Document` +// and this impl allows `&Document` to get coerced to `&aws_smithy_types::Document`. +// We should ideally handle this in `JsonSerializerGenerator.kt` but I'm not sure how hard it is. +impl Deref for Document { + type Target = aws_smithy_types::Document; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl From for Document { + fn from(other: aws_smithy_types::Document) -> Document { + Document(other) + } +} + #[cfg(test)] mod tests { use pyo3::py_run;