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

image: impl From<MediaType> for String #146

Merged
merged 2 commits into from
Oct 4, 2023

Conversation

waynr
Copy link
Contributor

@waynr waynr commented Sep 28, 2023

I considered converting the media type strings to constants so they can be
referenced without allocating a String but since these types aren't
comprehensive (ie we always have to deal with unknown types so we could never
impl From<String> for &'static str) I don't think that's necessary.

Signed-off-by: wayne warren wayne.warren.s@gmail.com

Signed-off-by: wayne warren <wayne.warren.s@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Sep 28, 2023

Codecov Report

Merging #146 (867ff92) into main (c109fe1) will decrease coverage by 0.19%.
The diff coverage is 0.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #146      +/-   ##
==========================================
- Coverage   22.61%   22.43%   -0.19%     
==========================================
  Files          23       23              
  Lines        2069     2086      +17     
  Branches     1146     1148       +2     
==========================================
  Hits          468      468              
- Misses        791      808      +17     
  Partials      810      810              

src/image/mod.rs Outdated
Comment on lines 128 to 153
impl From<MediaType> for String {
fn from(media_type: MediaType) -> Self {
match media_type {
MediaType::Descriptor => "application/vnd.oci.descriptor".to_string(),
MediaType::LayoutHeader => "application/vnd.oci.layout.header.v1+json".to_string(),
MediaType::ImageManifest => "application/vnd.oci.image.manifest.v1+json".to_string(),
MediaType::ImageIndex => "application/vnd.oci.image.index.v1+json".to_string(),
MediaType::ImageLayer => "application/vnd.oci.image.layer.v1.tar".to_string(),
MediaType::ImageLayerGzip => "application/vnd.oci.image.layer.v1.tar+gzip".to_string(),
MediaType::ImageLayerZstd => "application/vnd.oci.image.layer.v1.tar+zstd".to_string(),
MediaType::ImageLayerNonDistributable => {
"application/vnd.oci.image.layer.nondistributable.v1.tar".to_string()
}
MediaType::ImageLayerNonDistributableGzip => {
"application/vnd.oci.image.layer.nondistributable.v1.tar+gzip".to_string()
}
MediaType::ImageLayerNonDistributableZstd => {
"application/vnd.oci.image.layer.nondistributable.v1.tar+zstd".to_string()
}
MediaType::ImageConfig => "application/vnd.oci.image.config.v1+json".to_string(),
MediaType::ArtifactManifest => "application/vnd.oci.artifact.manifest.v1+json".to_string(),
MediaType::EmptyJSON => "application/vnd.oci.empty.v1+json".to_string(),
MediaType::Other(media) => media.to_string(),
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We have to apply rustfmt here:

diff --git a/src/image/mod.rs b/src/image/mod.rs
index 7c069c7..571e10c 100644
--- a/src/image/mod.rs
+++ b/src/image/mod.rs
@@ -145,7 +145,[9](https://github.com/containers/oci-spec-rs/actions/runs/6334296245/job/17203694086?pr=146#step:3:10) @@ impl From<MediaType> for String {
                 "application/vnd.oci.image.layer.nondistributable.v1.tar+zstd".to_string()
             }
             MediaType::ImageConfig => "application/vnd.oci.image.config.v1+json".to_string(),
-            MediaType::ArtifactManifest => "application/vnd.oci.artifact.manifest.v1+json".to_string(),
+            MediaType::ArtifactManifest => {
+                "application/vnd.oci.artifact.manifest.v1+json".to_string()
+            }
             MediaType::EmptyJSON => "application/vnd.oci.empty.v1+json".to_string(),
             MediaType::Other(media) => media.to_string(),
         }

@saschagrunert
Copy link
Contributor

@waynr may I ask you to squash your commits or sign-off the last one?

@waynr waynr force-pushed the impl-from-MediaType-for-String branch from 05ea4d3 to 867ff92 Compare October 2, 2023 16:04
Signed-off-by: wayne warren <wayne.warren.s@gmail.com>
@utam0k
Copy link
Member

utam0k commented Oct 3, 2023

@saschagrunert WDYT?

@saschagrunert saschagrunert merged commit abfd01c into youki-dev:main Oct 4, 2023
6 checks passed
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