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::DallE2 => "dall-e-2",
53 Self::DallE3 => "dall-e-3",
54 Self::GptImage1 => "gpt-image-1",
55 Self::GptImage1dot5 => "gpt-image-1.5",
56 Self::GptImage1Mini => "gpt-image-1-mini",
57 Self::Other(other) => other,
58 }
59 )
60 }
61}
62
63impl Display for ImageBackground {
64 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 write!(
66 f,
67 "{}",
68 match self {
69 Self::Transparent => "transparent",
70 Self::Opaque => "opaque",
71 Self::Auto => "auto",
72 }
73 )
74 }
75}
76
77impl Display for ImageOutputFormat {
78 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 write!(
80 f,
81 "{}",
82 match self {
83 Self::Png => "png",
84 Self::Jpeg => "jpeg",
85 Self::Webp => "webp",
86 }
87 )
88 }
89}
90
91impl Display for InputFidelity {
92 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
93 write!(
94 f,
95 "{}",
96 match self {
97 Self::High => "high",
98 Self::Low => "low",
99 }
100 )
101 }
102}
103
104impl Display for ImageQuality {
105 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
106 write!(
107 f,
108 "{}",
109 match self {
110 Self::Low => "low",
111 Self::Medium => "medium",
112 Self::High => "high",
113 Self::Auto => "auto",
114 Self::Standard => "standard",
115 Self::HD => "hd",
116 }
117 )
118 }
119}
120
121impl Display for ImageResponseFormat {
122 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
123 write!(
124 f,
125 "{}",
126 match self {
127 Self::Url => "url",
128 Self::B64Json => "b64_json",
129 }
130 )
131 }
132}
133
134impl Default for ImageEditInput {
135 fn default() -> Self {
136 Self::Image(ImageInput::default())
137 }
138}
139
140impl From<ImageInput> for ImageEditInput {
141 fn from(value: ImageInput) -> Self {
142 Self::Image(value)
143 }
144}
145
146impl From<Vec<ImageInput>> for ImageEditInput {
147 fn from(value: Vec<ImageInput>) -> Self {
148 Self::Images(value)
149 }
150}
151
152#[cfg(not(target_family = "wasm"))]
154impl From<&str> for ImageEditInput {
155 fn from(value: &str) -> Self {
156 Self::Image(value.into())
157 }
158}
159
160#[cfg(not(target_family = "wasm"))]
161impl From<String> for ImageEditInput {
162 fn from(value: String) -> Self {
163 Self::Image(value.into())
164 }
165}
166
167#[cfg(not(target_family = "wasm"))]
168impl From<&Path> for ImageEditInput {
169 fn from(value: &Path) -> Self {
170 Self::Image(value.into())
171 }
172}
173
174#[cfg(not(target_family = "wasm"))]
175impl From<PathBuf> for ImageEditInput {
176 fn from(value: PathBuf) -> Self {
177 Self::Image(value.into())
178 }
179}
180
181#[cfg(not(target_family = "wasm"))]
183impl<const N: usize> From<[&str; N]> for ImageEditInput {
184 fn from(value: [&str; N]) -> Self {
185 Self::Images(value.into_iter().map(ImageInput::from).collect())
186 }
187}
188
189#[cfg(not(target_family = "wasm"))]
190impl<const N: usize> From<[String; N]> for ImageEditInput {
191 fn from(value: [String; N]) -> Self {
192 Self::Images(value.into_iter().map(ImageInput::from).collect())
193 }
194}
195
196#[cfg(not(target_family = "wasm"))]
197impl<const N: usize> From<[&Path; N]> for ImageEditInput {
198 fn from(value: [&Path; N]) -> Self {
199 Self::Images(value.into_iter().map(ImageInput::from).collect())
200 }
201}
202
203#[cfg(not(target_family = "wasm"))]
204impl<const N: usize> From<[PathBuf; N]> for ImageEditInput {
205 fn from(value: [PathBuf; N]) -> Self {
206 Self::Images(value.into_iter().map(ImageInput::from).collect())
207 }
208}
209
210#[cfg(not(target_family = "wasm"))]
212impl<'a> From<Vec<&'a str>> for ImageEditInput {
213 fn from(value: Vec<&'a str>) -> Self {
214 Self::Images(value.into_iter().map(ImageInput::from).collect())
215 }
216}
217
218#[cfg(not(target_family = "wasm"))]
219impl From<Vec<String>> for ImageEditInput {
220 fn from(value: Vec<String>) -> Self {
221 Self::Images(value.into_iter().map(ImageInput::from).collect())
222 }
223}
224
225#[cfg(not(target_family = "wasm"))]
226impl From<Vec<&Path>> for ImageEditInput {
227 fn from(value: Vec<&Path>) -> Self {
228 Self::Images(value.into_iter().map(ImageInput::from).collect())
229 }
230}
231
232#[cfg(not(target_family = "wasm"))]
233impl From<Vec<PathBuf>> for ImageEditInput {
234 fn from(value: Vec<PathBuf>) -> Self {
235 Self::Images(value.into_iter().map(ImageInput::from).collect())
236 }
237}