Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-types"
version = "1.2.7"
version = "1.2.8"
authors = [
"AWS Rust SDK Team <[email protected]>",
"Russell Cohen <[email protected]>",
Expand Down
37 changes: 37 additions & 0 deletions rust-runtime/aws-smithy-types/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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",
Expand Down
Loading