From 382d7f5bc9c0df229ebc85f8564a594bc4718bf2 Mon Sep 17 00:00:00 2001 From: wayne warren Date: Wed, 27 Sep 2023 21:47:36 -0600 Subject: [PATCH 1/2] image: impl From for String Signed-off-by: wayne warren --- src/image/mod.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/image/mod.rs b/src/image/mod.rs index 2a5116eacd..7c069c7288 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -125,6 +125,33 @@ impl From<&str> for MediaType { } } +impl From 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(), + } + } +} + /// Trait to get the Docker Image Manifest V2 Schema 2 media type for an OCI media type /// /// This may be necessary for compatibility with tools that do not recognize the OCI media types. From 867ff92e6f8d428280f9f8063e76d6f4e9f2ebf7 Mon Sep 17 00:00:00 2001 From: wayne warren Date: Sun, 1 Oct 2023 06:31:41 -0600 Subject: [PATCH 2/2] obey rustfmt Signed-off-by: wayne warren --- src/image/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/image/mod.rs b/src/image/mod.rs index 7c069c7288..571e10c78a 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -145,7 +145,9 @@ impl From 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(), }