image
image copied to clipboard
Would ImageFormat::to_mime_type be valuable for this crate?
This crate already provides a ImageFormat::from_mime_type
function, but there is no counterpart (like to_mime_type
).
There are circumstances this would be very handy, like image manipulation web services, which need to provide MIME types as request/response headers.
If maintainers agree but don't have time, I can propose a PR.
Draft
impl ImageFormat {
// <snip>
pub fn to_mime_type(&self) -> Option<&'static str>
{
match self {
ImageFormat::Png => Some("image/png"),
// <snip>
}
}
Sounds good, please do. Directly discussing a PR has usually low friction for small changes that don't require larger design work / affect multiple components. In this case it seems fine. (The largest question is whether we expose it as a static string or a String
, or returning something that implements Display/ToString
similar to std::path::Path::display()
. But it's a lot simpler to return a static str and that covers all options, so I don't see any reason not to go with the draft interface).
This would be super helpful. I need to write out images and am managing this in my application.