Skip to content

Commit

Permalink
Merge pull request #146 from waynr/impl-from-MediaType-for-String
Browse files Browse the repository at this point in the history
image: impl From<MediaType> for String
  • Loading branch information
saschagrunert authored Oct 4, 2023
2 parents c109fe1 + 867ff92 commit abfd01c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ impl From<&str> for MediaType {
}
}

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(),
}
}
}

/// 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.
Expand Down

0 comments on commit abfd01c

Please sign in to comment.