use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct CodecId {
pub id: &'static str,
}
impl CodecId {
pub const fn new(id: &'static str) -> Self {
Self { id }
}
}
impl fmt::Display for CodecId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.id)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CodecDirection {
Encode,
Decode,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct CodecInfo {
pub id: CodecId,
pub version: String,
pub direction: CodecDirection,
}
impl CodecInfo {
pub fn new(id: CodecId, version: impl Into<String>, direction: CodecDirection) -> Self {
Self {
id,
version: version.into(),
direction,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MetadataEmbedOptions {
pub embed_exif: bool,
pub embed_icc: bool,
pub embed_xmp: bool,
}
impl MetadataEmbedOptions {
pub fn all() -> Self {
Self {
embed_exif: true,
embed_icc: true,
embed_xmp: true,
}
}
pub fn none() -> Self {
Self {
embed_exif: false,
embed_icc: false,
embed_xmp: false,
}
}
pub fn any(&self) -> bool {
self.embed_exif || self.embed_icc || self.embed_xmp
}
}
impl Default for MetadataEmbedOptions {
fn default() -> Self {
Self::all()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn codec_id_display() {
let id = CodecId::new("jpeg/mozjpeg");
assert_eq!(id.to_string(), "jpeg/mozjpeg");
}
#[test]
fn metadata_embed_constructors() {
assert_eq!(MetadataEmbedOptions::default(), MetadataEmbedOptions::all());
assert!(MetadataEmbedOptions::all().any());
assert!(!MetadataEmbedOptions::none().any());
}
}