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

Add serde support to Blob type #2647

Merged
merged 20 commits into from
Jun 6, 2023
Merged

Conversation

thomas-k-cameron
Copy link
Contributor

@thomas-k-cameron thomas-k-cameron commented Apr 27, 2023

Motivation and Context

This is a child PR of #2616

The changes that this PR introduces is same as the ones that were merged to unstable-serde-support branch before.

Initially, we tried to make commit to unstable-serde-support branch and merge changes one by one in small PRs. However, in order to make it up to date with the main branch, we would need to go through a large PR of over 700 files.

Thus, I decided to create individual PRs that commits directly to main branch.

Description

  • Implements serde support to Blob

Testing

  • Test checks whether the serialized/de-serialized data matches with the expected value

Checklist

NA


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@thomas-k-cameron thomas-k-cameron changed the title update blob.rs Add serde support to Blob type Apr 27, 2023
This was referenced Apr 27, 2023
@thomas-k-cameron thomas-k-cameron marked this pull request as ready for review April 27, 2023 02:24
@thomas-k-cameron thomas-k-cameron requested review from a team as code owners April 27, 2023 02:24
@@ -30,3 +40,122 @@ impl AsRef<[u8]> for Blob {
&self.inner
}
}

#[cfg(all(aws_sdk_unstable, feature = "serde-serialize"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about refactoring this into a module so you can feature gate it once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, why do you have both base64 and base64-simd?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only be using base64-simd, I think. base64 is there for this bench comparing base64 to base64-simd.

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation looks fine, would be nice to clean up the feature gating a little bit.

Side note—it would be good to add a test to aws-smithy-types additional ci to verify these other deps don't end up in the tree when the cfg gate isn't enabled

@thomas-k-cameron
Copy link
Contributor Author

thomas-k-cameron commented Apr 27, 2023

implementation looks fine, would be nice to clean up the feature gating a little bit.

Side note—it would be good to add a test to aws-smithy-types additional ci to verify these other deps don't end up in the tree when the cfg gate isn't enabled

Thank you for the suggestion.

You don't really have a way to check whether a struct implements a trait on runtime.
So I think you can't really do this.

Maybe check if you can compile when the features are not enabled?

Let me think about it for a bit.

thomas-k-cameron added a commit to thomas-k-cameron/smithy-rs that referenced this pull request Apr 27, 2023
@thomas-k-cameron
Copy link
Contributor Author

I added a test that checks whether the traits are properly feature gated by checking whether compilation would succeed.

It tries to compile these pieces of code.

fn main() {
    serde_json::to_string(&ReplaceDataType::default());
}
fn main() {
    let dt: Result<ReplaceDataType, _> = serde_json::from_str("some_str");
}

If cargo check doesn't work, than that means that traits are properly feature gated.

@thomas-k-cameron
Copy link
Contributor Author

I refactor the code.
It should be lot more readable.

@@ -0,0 +1,228 @@
/*
Copy link
Collaborator

@rcoh rcoh May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although very clever, I think we can do something much simpler by adding something like adding:

cargo tree -e no-dev | grep serde to the additional-ci script in this directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's sounds simpler.
I updated.

Let me know if I didn't understand you correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these code to the script.

# checks whether the features are properly feature-gated
res=$(cargo tree -e no-dev | grep serde) 
if [ "$res" != "" ]; then
    exit 1
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I didn't know that grep gives you an error when it can't find a match.

I fixed it up

set -e

echo "### Checking for duplicate dependency versions in the normal dependency graph with all features enabled"
cargo tree -d --edges normal --all-features

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be working now.

@thomas-k-cameron thomas-k-cameron requested a review from rcoh May 8, 2023 16:50
Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just some minor suggestions.

rust-runtime/aws-smithy-types/src/blob.rs Outdated Show resolved Hide resolved
rust-runtime/aws-smithy-types/src/blob.rs Outdated Show resolved Hide resolved
@jdisanti
Copy link
Collaborator

jdisanti commented Jun 6, 2023

Thank you for the contribution! ❤️

@jdisanti jdisanti added this pull request to the merge queue Jun 6, 2023
Merged via the queue into smithy-lang:main with commit 77395c3 Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants