Unverified Commit ef07c887 authored by Andrew Jewell's avatar Andrew Jewell Committed by GitHub
Browse files

chore: add Into conversions for Blob to [u8] (#3877)

## Motivation and Context
Often I have a &[u8] or a Vec<u8>, but the sdk function takes a Blob.
It would be convenient to pass the my_vec instead of
aws_smithy_types::Blob::new(my_vec)

## Description
In blob.rs I added
Into<Vec<u8>> for Blob
Into<Blob> for Vec<u8>
Into<Blob> for &[u8]


## Testing
Added a test to blob.rs to test the various scenarios.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 8e8101a7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
[package]
name = "aws-smithy-types"
version = "1.2.7"
version = "1.2.8"
authors = [
    "AWS Rust SDK Team <aws-sdk-rust@amazon.com>",
    "Russell Cohen <rcoh@amazon.com>",
+37 −0
Original line number Diff line number Diff line
@@ -31,6 +31,24 @@ impl AsRef<[u8]> for Blob {
    }
}

impl From<Vec<u8>> for Blob {
    fn from(value: Vec<u8>) -> Self {
        Blob::new(value)
    }
}

impl From<Blob> for Vec<u8> {
    fn from(value: Blob) -> Self {
        value.into_inner()
    }
}

impl From<&[u8]> for Blob {
    fn from(value: &[u8]) -> Self {
        Blob::new(value)
    }
}

#[cfg(all(aws_sdk_unstable, feature = "serde-serialize"))]
mod serde_serialize {
    use super::*;
@@ -103,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<u8> = blob1.into();
        assert_eq!(orig_vec, vec1);

        let blob2: Blob = my_vec.into();
        let vec2: Vec<u8> = blob2.into();
        assert_eq!(orig_vec, vec2);
    }
}

#[cfg(all(
    aws_sdk_unstable,
    feature = "serde-serialize",