1use std::fmt;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize))]
17pub struct CodecId {
18 pub id: &'static str,
20}
21
22impl CodecId {
23 pub const fn new(id: &'static str) -> Self {
25 Self { id }
26 }
27}
28
29impl fmt::Display for CodecId {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 f.write_str(self.id)
32 }
33}
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
37#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
38pub enum CodecDirection {
39 Encode,
41 Decode,
43}
44
45#[derive(Debug, Clone, PartialEq, Eq, Hash)]
50#[cfg_attr(feature = "serde", derive(serde::Serialize))]
51pub struct CodecInfo {
52 pub id: CodecId,
54 pub version: String,
57 pub direction: CodecDirection,
59}
60
61impl CodecInfo {
62 pub fn new(id: CodecId, version: impl Into<String>, direction: CodecDirection) -> Self {
64 Self {
65 id,
66 version: version.into(),
67 direction,
68 }
69 }
70}
71
72#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
75pub struct MetadataEmbedOptions {
76 pub embed_exif: bool,
78 pub embed_icc: bool,
80 pub embed_xmp: bool,
82}
83
84impl MetadataEmbedOptions {
85 pub fn all() -> Self {
87 Self {
88 embed_exif: true,
89 embed_icc: true,
90 embed_xmp: true,
91 }
92 }
93
94 pub fn none() -> Self {
96 Self {
97 embed_exif: false,
98 embed_icc: false,
99 embed_xmp: false,
100 }
101 }
102
103 pub fn any(&self) -> bool {
105 self.embed_exif || self.embed_icc || self.embed_xmp
106 }
107}
108
109impl Default for MetadataEmbedOptions {
110 fn default() -> Self {
111 Self::all()
112 }
113}
114
115#[cfg(test)]
116mod tests {
117 use super::*;
118
119 #[test]
120 fn codec_id_display() {
121 let id = CodecId::new("jpeg/mozjpeg");
122 assert_eq!(id.to_string(), "jpeg/mozjpeg");
123 }
124
125 #[test]
126 fn metadata_embed_constructors() {
127 assert_eq!(MetadataEmbedOptions::default(), MetadataEmbedOptions::all());
128 assert!(MetadataEmbedOptions::all().any());
129 assert!(!MetadataEmbedOptions::none().any());
130 }
131}