async_openai/types/images/
impls.rs

1use std::fmt::Display;
2
3#[cfg(not(target_family = "wasm"))]
4use std::path::{Path, PathBuf};
5
6use crate::types::images::{
7    DallE2ImageSize, ImageBackground, ImageEditInput, ImageInput, ImageModel, ImageOutputFormat,
8    ImageQuality, ImageResponseFormat, ImageSize, InputFidelity,
9};
10
11impl Display for ImageSize {
12    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13        write!(
14            f,
15            "{}",
16            match self {
17                Self::S256x256 => "256x256",
18                Self::S512x512 => "512x512",
19                Self::S1024x1024 => "1024x1024",
20                Self::S1792x1024 => "1792x1024",
21                Self::S1024x1792 => "1024x1792",
22                Self::S1536x1024 => "1536x1024",
23                Self::S1024x1536 => "1024x1536",
24                Self::Auto => "auto",
25            }
26        )
27    }
28}
29
30impl Display for DallE2ImageSize {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        write!(
33            f,
34            "{}",
35            match self {
36                Self::S256x256 => "256x256",
37                Self::S512x512 => "512x512",
38                Self::S1024x1024 => "1024x1024",
39            }
40        )
41    }
42}
43
44impl Display for ImageModel {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        write!(
47            f,
48            "{}",
49            match self {
50                Self::DallE2 => "dall-e-2",
51                Self::DallE3 => "dall-e-3",
52                Self::GptImage1 => "gpt-image-1",
53                Self::GptImage1dot5 => "gpt-image-1.5",
54                Self::GptImage1Mini => "gpt-image-1-mini",
55                Self::Other(other) => other,
56            }
57        )
58    }
59}
60
61impl Display for ImageBackground {
62    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63        write!(
64            f,
65            "{}",
66            match self {
67                Self::Transparent => "transparent",
68                Self::Opaque => "opaque",
69                Self::Auto => "auto",
70            }
71        )
72    }
73}
74
75impl Display for ImageOutputFormat {
76    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77        write!(
78            f,
79            "{}",
80            match self {
81                Self::Png => "png",
82                Self::Jpeg => "jpeg",
83                Self::Webp => "webp",
84            }
85        )
86    }
87}
88
89impl Display for InputFidelity {
90    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91        write!(
92            f,
93            "{}",
94            match self {
95                Self::High => "high",
96                Self::Low => "low",
97            }
98        )
99    }
100}
101
102impl Display for ImageQuality {
103    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
104        write!(
105            f,
106            "{}",
107            match self {
108                Self::Low => "low",
109                Self::Medium => "medium",
110                Self::High => "high",
111                Self::Auto => "auto",
112                Self::Standard => "standard",
113                Self::HD => "hd",
114            }
115        )
116    }
117}
118
119impl Display for ImageResponseFormat {
120    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
121        write!(
122            f,
123            "{}",
124            match self {
125                Self::Url => "url",
126                Self::B64Json => "b64_json",
127            }
128        )
129    }
130}
131
132impl Default for ImageEditInput {
133    fn default() -> Self {
134        Self::Image(ImageInput::default())
135    }
136}
137
138impl From<ImageInput> for ImageEditInput {
139    fn from(value: ImageInput) -> Self {
140        Self::Image(value)
141    }
142}
143
144impl From<Vec<ImageInput>> for ImageEditInput {
145    fn from(value: Vec<ImageInput>) -> Self {
146        Self::Images(value)
147    }
148}
149
150// Single path-like values (not available in WASM)
151#[cfg(not(target_family = "wasm"))]
152impl From<&str> for ImageEditInput {
153    fn from(value: &str) -> Self {
154        Self::Image(value.into())
155    }
156}
157
158#[cfg(not(target_family = "wasm"))]
159impl From<String> for ImageEditInput {
160    fn from(value: String) -> Self {
161        Self::Image(value.into())
162    }
163}
164
165#[cfg(not(target_family = "wasm"))]
166impl From<&Path> for ImageEditInput {
167    fn from(value: &Path) -> Self {
168        Self::Image(value.into())
169    }
170}
171
172#[cfg(not(target_family = "wasm"))]
173impl From<PathBuf> for ImageEditInput {
174    fn from(value: PathBuf) -> Self {
175        Self::Image(value.into())
176    }
177}
178
179// Arrays of path-like values (not available in WASM)
180#[cfg(not(target_family = "wasm"))]
181impl<const N: usize> From<[&str; N]> for ImageEditInput {
182    fn from(value: [&str; N]) -> Self {
183        Self::Images(value.into_iter().map(ImageInput::from).collect())
184    }
185}
186
187#[cfg(not(target_family = "wasm"))]
188impl<const N: usize> From<[String; N]> for ImageEditInput {
189    fn from(value: [String; N]) -> Self {
190        Self::Images(value.into_iter().map(ImageInput::from).collect())
191    }
192}
193
194#[cfg(not(target_family = "wasm"))]
195impl<const N: usize> From<[&Path; N]> for ImageEditInput {
196    fn from(value: [&Path; N]) -> Self {
197        Self::Images(value.into_iter().map(ImageInput::from).collect())
198    }
199}
200
201#[cfg(not(target_family = "wasm"))]
202impl<const N: usize> From<[PathBuf; N]> for ImageEditInput {
203    fn from(value: [PathBuf; N]) -> Self {
204        Self::Images(value.into_iter().map(ImageInput::from).collect())
205    }
206}
207
208// Vectors of path-like values (not available in WASM)
209#[cfg(not(target_family = "wasm"))]
210impl<'a> From<Vec<&'a str>> for ImageEditInput {
211    fn from(value: Vec<&'a str>) -> Self {
212        Self::Images(value.into_iter().map(ImageInput::from).collect())
213    }
214}
215
216#[cfg(not(target_family = "wasm"))]
217impl From<Vec<String>> for ImageEditInput {
218    fn from(value: Vec<String>) -> Self {
219        Self::Images(value.into_iter().map(ImageInput::from).collect())
220    }
221}
222
223#[cfg(not(target_family = "wasm"))]
224impl From<Vec<&Path>> for ImageEditInput {
225    fn from(value: Vec<&Path>) -> Self {
226        Self::Images(value.into_iter().map(ImageInput::from).collect())
227    }
228}
229
230#[cfg(not(target_family = "wasm"))]
231impl From<Vec<PathBuf>> for ImageEditInput {
232    fn from(value: Vec<PathBuf>) -> Self {
233        Self::Images(value.into_iter().map(ImageInput::from).collect())
234    }
235}