From 6172d3b0091c653fe1aabca4d0fb05aa3daac5e5 Mon Sep 17 00:00:00 2001 From: Andy Jewell Date: Tue, 15 Oct 2024 15:07:51 -0400 Subject: [PATCH] add test --- rust-runtime/aws-smithy-types/src/blob.rs | 37 +++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/rust-runtime/aws-smithy-types/src/blob.rs b/rust-runtime/aws-smithy-types/src/blob.rs index d63dc7ca28..f6ba16fda4 100644 --- a/rust-runtime/aws-smithy-types/src/blob.rs +++ b/rust-runtime/aws-smithy-types/src/blob.rs @@ -31,21 +31,21 @@ impl AsRef<[u8]> for Blob { } } -impl Into> for Blob { - fn into(self) -> Vec { - self.into_inner() +impl From> for Blob { + fn from(value: Vec) -> Self { + Blob::new(value) } } -impl Into for Vec { - fn into(self) -> Blob { - Blob::new(self) +impl From for Vec { + fn from(value: Blob) -> Self { + value.into_inner() } } -impl Into for &[u8] { - fn into(self) -> Blob { - Blob::new(self) +impl From<&[u8]> for Blob { + fn from(value: &[u8]) -> Self { + Blob::new(value) } } @@ -121,6 +121,25 @@ mod serde_deserialize { } #[cfg(test)] +mod test { + use crate::Blob; + + #[test] + fn blob_conversion() { + let my_bytes: &[u8] = &[1u8, 2u8, 3u8]; + let my_vec = vec![1u8, 2u8, 3u8]; + let orig_vec = my_vec.clone(); + + let blob1: Blob = my_bytes.into(); + let vec1: Vec = blob1.into(); + assert_eq!(orig_vec, vec1); + + let blob2: Blob = my_vec.into(); + let vec2: Vec = blob2.into(); + assert_eq!(orig_vec, vec2); + } +} + #[cfg(all( aws_sdk_unstable, feature = "serde-serialize",