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