#[non_exhaustive]pub enum ImageFormat {
Png,
Jpeg,
Gif,
Bmp,
Wmf,
Emf,
Unknown(String),
}Expand description
Supported image formats.
Marked #[non_exhaustive] so new formats can be added in future
phases without a breaking change.
§Examples
use hwpforge_core::image::ImageFormat;
let fmt = ImageFormat::Png;
assert_eq!(fmt.to_string(), "PNG");
let unknown = ImageFormat::Unknown("SVG".to_string());
assert_eq!(unknown.to_string(), "svg");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Png
Portable Network Graphics.
Jpeg
JPEG.
Gif
Graphics Interchange Format.
Bmp
Windows Bitmap.
Wmf
Windows Metafile.
Emf
Enhanced Metafile.
Unknown(String)
Unrecognized format with its extension or MIME type.
Implementations§
Source§impl ImageFormat
impl ImageFormat
Sourcepub fn from_extension(path: &str) -> Self
pub fn from_extension(path: &str) -> Self
Infers an ImageFormat from a file path’s extension.
The extension is extracted from everything after the last '.' in the
path string and matched case-insensitively. If no dot is found, or the
extension is not recognized, ImageFormat::Unknown is returned
containing the lowercase extension (or an empty string when absent).
§Examples
use hwpforge_core::image::ImageFormat;
assert_eq!(ImageFormat::from_extension("photo.png"), ImageFormat::Png);
assert_eq!(ImageFormat::from_extension("image.JPG"), ImageFormat::Jpeg);
assert_eq!(ImageFormat::from_extension("file.jpeg"), ImageFormat::Jpeg);
assert_eq!(ImageFormat::from_extension("doc.gif"), ImageFormat::Gif);
assert_eq!(ImageFormat::from_extension("img.bmp"), ImageFormat::Bmp);
assert_eq!(ImageFormat::from_extension("chart.wmf"), ImageFormat::Wmf);
assert_eq!(ImageFormat::from_extension("dia.emf"), ImageFormat::Emf);
assert_eq!(
ImageFormat::from_extension("file.xyz"),
ImageFormat::Unknown("xyz".to_string()),
);
assert_eq!(
ImageFormat::from_extension("noext"),
ImageFormat::Unknown(String::new()),
);
assert_eq!(ImageFormat::from_extension("multi.dot.png"), ImageFormat::Png);Trait Implementations§
Source§impl Clone for ImageFormat
impl Clone for ImageFormat
Source§fn clone(&self) -> ImageFormat
fn clone(&self) -> ImageFormat
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ImageFormat
impl Debug for ImageFormat
Source§impl<'de> Deserialize<'de> for ImageFormat
impl<'de> Deserialize<'de> for ImageFormat
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for ImageFormat
impl Display for ImageFormat
Source§impl Hash for ImageFormat
impl Hash for ImageFormat
Source§impl JsonSchema for ImageFormat
impl JsonSchema for ImageFormat
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreSource§impl PartialEq for ImageFormat
impl PartialEq for ImageFormat
Source§impl Serialize for ImageFormat
impl Serialize for ImageFormat
impl Eq for ImageFormat
impl StructuralPartialEq for ImageFormat
Auto Trait Implementations§
impl Freeze for ImageFormat
impl RefUnwindSafe for ImageFormat
impl Send for ImageFormat
impl Sync for ImageFormat
impl Unpin for ImageFormat
impl UnwindSafe for ImageFormat
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.